/** * Sets up a session handler * @param string $class name of the handler class */ protected static function setupHandler($class) { Pfw_Loader::loadClass($class); $a = new $class(); session_set_save_handler(array($a, 'open'), array($a, 'close'), array($a, 'read'), array($a, 'write'), array($a, 'destroy'), array($a, 'gc')); self::$adapter = $a; }
function setupView() { $view = $this->getView(); $view->assign('controller', Pfw_Request::getParam('controller')); if (self::is_logged_in()) { # gettng user with profile photo Pfw_Loader::loadModel('User'); $user = User::Q()->where(array('this.id = %s', Pfw_Session::get('login_id')))->exec(); $logged_in_user = $user[0]; $view->assign('logged_in_user', $logged_in_user); $view->assign('is_logged_in', true); } }
function createAction() { $project = new Project(); $project->name = $_REQUEST['project_name']; $project->description = $_REQUEST['project_desc']; $project->dt_created = mysql_time(); $project->created_by = Pfw_Session::get('login_id'); try { $project->save(); } catch (Exception $e) { error_log("Caught exception with [" . $e->getMessage() . "]"); } $this->redirect("/home"); return; }
<?php /** * Add a project specific startup here */ global $_PATHS, $_ENVIRONMENT; Pfw_Loader::loadFile("pfw_routes.php", $_PATHS['conf']); Pfw_Loader::loadClass('Pfw_Controller_Front'); Pfw_Loader::loadClass('Pfw_PluginManager'); Pfw_Loader::loadClass('Pfw_Session'); Pfw_Loader::loadClass('Pfw_Alert'); // initialize the session Pfw_Session::start(); // initialize the plugin manager Pfw_PluginManager::init(); // initialize alerts Pfw_Alert::init(); // turn off error display for production if ($_ENVIRONMENT == "production") { ini_set('display_errors', 0); ini_set('log_errors', 1); } // setup front controller and routing $front = Pfw_Controller_Front::getInstance(); $front->getRouter()->setRoutes($_pfw_routes)->setModules($_pfw_modules); $four_oh_four = false; try { $front->dispatch(); } catch (Pfw_Exception_System $e) { $e->emitLog(); if ($_ENVIRONMENT == "development") {
/** * Internal method to clear all alerts/notices with optional field. * * @param const $type self::TYPE_ERROR or self::TYPE_NOTICE * @param string $field */ protected static function clear($type, $field) { self::assertInitialized(); $alerts = Pfw_Session::get(self::SESSION_KEY); if (!empty($alerts)) { if (null !== field) { self::deleteWithFieldFromArray($alerts[$type], $field); } else { $alerts[$type] = array(); } Pfw_Sesssion::set(self::SESSION_KEY, $alerts); } if (null !== $field) { self::deleteWithFieldFromArray(self::$alerts[$type], $field); } else { self::$alerts[$type] = array(); } }
/** * Logout */ function logoutAction() { Pfw_Session::set('is_logged_in', false); Pfw_Session::clear('login_id'); $this->redirect('/user/login'); }