如何在zend中从一个控制器获取Zend_registry的值到其他控制器?

时间:2015-05-12 09:11:08

标签: zend-framework

我使用以下方法从一个控制器获取Zend_registry值但没有成功。我是否需要在bootstrap.php或其他文件中启动Zend_registry,我可以在两个或更多文件之间使用它。 / p>

$registry = Zend_Registry::getInstance();
$registry->set('variableName', 'value');
or
Zend_Registry::set('variableName', $value);

And this is how you get the value

$registry = Zend_Registry::getInstance();
$registry->get('variableName');
or
Zend_Registry::get('variableName');

获得多个数组

$value = array("name" =>'pankaj',"post" =>'sendeveloper');                         
Zend_Registry::get('session')->variableName = $value;

$value1 = array("name" =>'rahul',"post" =>'jndeveloper');                         
Zend_Registry::get('session')->variableTable = $value;

$value3 = array("name" =>'vonod',"post" =>'techdeveloper');                         
Zend_Registry::get('session')->variabletech = $value;

似乎只使用variableName而不是其他。我需要做什么?

1 个答案:

答案 0 :(得分:1)

要解决此问题,我使用Zend_Registry Zend_Session_Namespace

在引导程序中:

protected function _initSession()
{
    Zend_Registry::set('session', new Zend_Session_Namespace("doydoy44"));
}

UserController

$value = array("name" =>'pankaj',"post" =>'developer'); 

Zend_Registry::get('session')->variableName = $value;  

CustomerController

var_dump(Zend_Registry::get('session')->variableName);