/** * * @param \Zend\Db\TableGateway\TableGateway $tableGateway */ public function __construct(\Zend\Db\TableGateway\TableGateway $tableGateway) { $this->tableGateway = $tableGateway; $session = new \Zend\Session\Container(); $this->id = $session->offsetGet('id'); $this->role = $session->offsetGet('role'); }
/** * Constructor */ public function __construct() { $this->msg = $this->flashMessenger()->getCurrentMessages(); $this->flashMessenger()->clearMessages(); $session = new \Zend\Session\Container(); $this->role = $session->offsetGet('role'); $this->id = $session->offsetGet('id'); }
/** * Constructor * @param \Zend\Db\TableGateway\TableGateway $tableGateway */ public function __construct(TableGateway $tableGateway) { $this->tableGateway = $tableGateway; $session = new \Zend\Session\Container(); $this->id = $session->offsetGet('id'); $this->role = $session->offsetGet('role'); $adapter = $this->tableGateway->getAdapter(); $this->sql = new Sql($adapter); }
/** * Return cart content * * @return array */ public function cart() { $items = $this->session->offsetGet('cart'); if (empty($items)) { return array(); } return $items; }
function userMessageAction() { $sessionContainer = new \Zend\Session\Container(); $user = $sessionContainer->offsetGet("user"); $username = $user['username']; $userMessage = $this->getUserMessageTable()->getUserMessage($username); return ['userMessage' => $userMessage]; }
/** * __invoke * * @access public * @param array $options array of options * @return string */ public function __invoke($url, $parentId) { $form = $this->getCommentForm(); $form->get('url')->setAttribute('value', $url); $container = new \Zend\Session\Container(); $errors = $container->offsetGet('form_errors'); if (isset($errors)) { $form->setMessages($errors); } $container->offsetUnset('form_errors'); $vm = new ViewModel(array('form' => $form, 'url' => $url, 'parentId' => $parentId)); $vm->setTemplate('comment/comment/index'); return $this->getView()->render($vm); }
<?php require_once './autoloader.php'; require_once EVA_LIB_PATH . '/Markdown/markdownextra.php'; $sm1 = new Zend\Session\SessionManager(); $sm1->setId(md5('session1')); $sessionContainer1 = new Zend\Session\Container('Namespace', $sm1); $sessionContainer1->offsetSet('testKey', 'foo'); echo $sessionContainer1->offsetGet('testKey'); //output foo $sm2 = new Zend\Session\SessionManager(); $sm2->setId(md5('session2')); /* $sessionContainer2 = new Zend\Session\Container('Namespace', $sm2); $sessionContainer2->offsetSet('testKey', 'bar'); echo $sessionContainer2->offsetGet('testKey'); //output bar */
/** * Check whether the current login is done via cookie * * Should be performed before allowing to change PW, access Financial Information etc. * * @return Boolean */ public function isCookieLogin() { $session = new \Zend\Session\Container('zfcuser'); return $session->offsetGet("cookieLogin"); }
public function _init(Dispatcher $dispatcher) { // 引入Composer,Yaf扩展的配置项yaf.use_spl_autoload务必设置为1 if (file_exists(ROOT_PATH . '/vendor/autoload.php')) { $loader = (include ROOT_PATH . '/vendor/autoload.php'); //$loader->add("",ROOT_PATH.'/library'); //$loader->addPsr4("Zend\\",ROOT_PATH.'/library/Zend'); Registry::set('loader', $loader); } // 禁止自动渲染 $dispatcher->autoRender(FALSE); // 保存配置 $this->_config = Application::app()->getConfig(); Registry::set('config', $this->_config); // 报错设置 if ($this->_config->global->showError) { error_reporting(-1); ini_set('display_errors', 'On'); } // 加解密 if (!empty($this->_config->global->key)) { Registry::set('enc', function () { $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes')); $blockCipher->setKey($this->_config->global->key); return $blockCipher; }); } // 命令行方式,跳过SESSION if (!defined("RUN_IN_CLI")) { // 保存路径 $sessionConfig = $this->_config->session->toArray(); if (isset($sessionConfig['save_path'])) { @mkdir($sessionConfig['save_path'], 0777, true); } // 配置 $config = new SessionConfig(); $config->setOptions($sessionConfig); // 会话管理器 $manager = new SessionManager($config); // 开启会话 $manager->start(); // 验证会话 $manager->getValidatorChain()->attach('session.validate', array(new HttpUserAgent(), 'isValid')); if (!$manager->isValid()) { $manager->destroy(); throw new \Exception("会话验证失败"); } // 会话Token $default = new Zend\Session\Container(); if (empty($default->offsetGet('securityToken'))) { $default->offsetSet('securityToken', md5(uniqid(rand(), true))); } // 保存实例 Registry::set('session', $default); Registry::set('sm', $manager); } // 数据库 Registry::set('db', function () { $mysqlMasterConfig = $this->_config->mysql->master->toArray(); $adapter = new Adapter($mysqlMasterConfig); $connect = $adapter->getDriver()->getConnection(); for ($i = 0; $i < 5; $i++) { if ($connect->isConnected()) { break; } $connect->connect(); } return $adapter; }); // 邮件 Registry::set('mail', function () { $options = new SmtpOptions($this->_config->smtp->toArray()); $mail = new SmtpTransport(); $mail->setOptions($options); return $mail; }); // 日志 Registry::set('logger', function () { $logger = new Zend\Log\Logger(); $writer = new Zend\Log\Writer\Stream($this->_config->log->path . '/' . date("Ymd") . ".log"); $logger->addWriter($writer); return $logger; }); }
/** * __invoke * * @access public * @param string * @return String */ public function __invoke() { $userSession = new \Zend\Session\Container('user'); $userName = $userSession->offsetGet('userData'); return $userName; }