我想從layout.xml訪問會話值。如何在Zend框架1中獲取佈局中的會話值?
我做的代碼是
Layout.xml
<h2><?php $myprofile=new Zend_Session('user_session');
print $myprofile->username; ?> </h2>
指數控制器/ index動作
$userid = $this->_user->getUserId($username,$password);
$session = new Zend_Session_Namespace('user_session');
$session->username = $username;
$session->password = $password;
$session->uid = $userid;
$this->_redirect('home');
首頁控制器/ index動作
$this->session = new Zend_Session_Namespace('user_session');
$this->view->uname = $this->session->username;
首頁/指數.phtml
<?php echo "The User Name is ".$this->uname?>
但它顯示了一個錯誤
Fatal error: Call to protected Zend_Session::__construct() from context 'Zend_View' in/var/www/shoppingcart/application/layouts/scripts/layout.phtml on line 19
我能夠獲得首頁/ index.html中的會話值。
期待積極幫助..
爲什麼downvote?
我正在使用的佈局會使其顯示在用戶登錄後的每一頁。 –