Php Zend框架中会话变量的引导和访问
通过ZF中的不同操作访问会话变量时出现问题 以下是引导程序的内容:Php Zend框架中会话变量的引导和访问,php,zend-framework,session,zend-session,Php,Zend Framework,Session,Zend Session,通过ZF中的不同操作访问会话变量时出现问题 以下是引导程序的内容: class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected function _initSession() { Zend_Session::start(); $sessionUser = new Zend_Session_Namespace('sessionUser');
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initSession()
{
Zend_Session::start();
$sessionUser = new Zend_Session_Namespace('sessionUser');
}
}
我在IndexController中为$sessionUser分配了一个变量:
$sessionUser->userId = $res->userId;
$sessionUser->organisationId = $res->organisation_organisationId;
$sessionUser->forename = $res->forename;
$sessionUser->organisationId
$sessionUser = new Zend_Session_Namespace('sessionUser');
并尝试访问管理员控制器中的变量:
$sessionUser->userId = $res->userId;
$sessionUser->organisationId = $res->organisation_organisationId;
$sessionUser->forename = $res->forename;
$sessionUser->organisationId
$sessionUser = new Zend_Session_Namespace('sessionUser');
但我收到了错误:
Notice: Undefined variable: sessionUser in /usr/local/zend/apache2/htdocs/SA1/application/controllers/AdministratorController.php on line 17 Notice: Trying to get property of non-object in /usr/local/zend/apache2/htdocs/SA1/application/controllers/AdministratorController.php on line 17
想法是什么导致了这一切
非常感谢要将会话变量恢复到控制器中,您还需要执行以下操作:
$sessionUser = new Zend_Session_Namespace('sessionUser');
你所犯的错误是显而易见的。未定义$sessionUser 在将值分配给该变量之前,必须初始化该变量。将其放入控制器:
$sessionUser->userId = $res->userId;
$sessionUser->organisationId = $res->organisation_organisationId;
$sessionUser->forename = $res->forename;
$sessionUser->organisationId
$sessionUser = new Zend_Session_Namespace('sessionUser');
该死,你打字比我快啊!我假设在引导中定义变量将使所有控制器都可以使用它。谢谢你的帮助。谢谢Richard,通过将作业插入控制器,现在已将其排序。