Define variables outside the PHP class

后端 未结 3 1435
感动是毒
感动是毒 2021-01-24 08:15

I m using zend.

I want to define the below code outside the controller class & access in different Actions.

$user = new Zend_Session_Namespace(\'user         


        
3条回答
  •  我在风中等你
    2021-01-24 08:43

    You can store the user in many ways and access it in more clean manner. You can store it in Zend_Registry and then use Zend_Registry::get('user') where you need to retrieve the user. You can also store it as a parameter of request object, and then in a controller simply do $user = $this->_getParam('user');

    If you need access to the user array in many controllers that inherit from the SystemadminController, what you can do is store it as a protected property of the SystemadminController (eg. protected $_user). Then all you need to do in child controllers is access $this->_user.

提交回复
热议问题