I've found that it's easier to assign the session namespace object to a
class property instead of instantiating it in each method. The init() method
in Zend_Controller_Action is great for this. I also use a class constant for
the namespace name just in case I need it in one of the other methods:
class AuthController extends Zend_Controller_Action
{
const SESSION_NAMESPACE = 'userRegister';
protected $_session;
public function init()
{
$this->_session = new
Zend_Session_Namespace(self::SESSION_NAMESPACE);
}
}
Instead of testing if the namespace exists, you can now test if the property
in the namespace exists:
public function onregistersuccessAction()
{
if (!isset($this->_session->user)) {
return $this->_helper->redirector('index');
}
/* ... */
}
I hope this helps :)
--
Hector
On Sat, Sep 12, 2009 at 4:13 AM, whisher <[email protected]> wrote:
> Hi.
>
> In the registerAction I set my namespace
>
> $userRegisterSession = new Zend_Session_Namespace('userRegister');
> $userRegisterSession->user = $data;
> return $this->_helper->redirector('onregistersuccess');;
>
> Than I need to retrieve the data so
>
> public function onregistersuccessAction()
> {
> if(!Zend_Session::namespaceIsset('userRegister')){
> return $this->_helper->redirector('index');
> }
>
> $this->view->headTitle($this->translator->translate('user_Register_HeadTitle_onsuccess'));
> $userRegisterSession = new Zend_Session_Namespace('userRegister');
> var_dump($userRegisterSession->getIterator());
>
> }
>
>
> As Zend_Session::_namespaceGet('userRegister') is deprecated, I don't find an
> other way.( Indeed, it's a very ugly way)
>
> I figure out there will be a more smart way.
>
> Can you give me an example ?
>
> Thanks in advance
>
> Bye
>
> ------------------------------
>
> View this message in context: How to get session namespace value
> <http://www.nabble.com/How-to-get-session-namespace-value-tp25413546p25413546.html>
>
> Sent from the Zend Framework mailing list archive
> <http://www.nabble.com/Zend-Framework-f15440.html> at Nabble.com.
>
>