0

I am trying to get the session value in another controller but don't get value from the session:

class Vaibhav_User_IndexController extends Mage_Core_Controller_Front_Action
  {
    public function loginAction()
{
    $data = $this->getRequest()->getParams();
    $model = Mage::getModel('user/user')->load($data['login']['username'],'email');
    if($model->getPassword() == $data['login']['password'])
    {

        if($model->getUserType() == 2)
        {
            Mage::getSingleton('core/session')->setLogiusername($model->getUserId());
            $this->_redirect('user/vendor/index');
            return ;
        }
    }
    else{
        Mage::getSingleton('core/session')->addError('Invalid Email Id or Password.');
        $this->_redirect('*/*/');
        return;
    }
}
}




class Vaibhav_User_VendorController extends Mage_Core_Controller_Front_Action
{
    public function preDispatch() 
    {

    }
    public function indexAction()
{
    echo Mage::getSingleton('core/session')->getLogiusername();
    exit;
}
}
  • In which order/context are those controllers called? – Anna Völkl Aug 31 '15 at 18:17
  • Edit question... – Vaibhav Ahalpara Sep 1 '15 at 6:00
2

Set session using this code

$session = Mage::getSingleton("core/session",  array("name"=>"frontend"));
$session->setData("user_id", $userid);

and then get session using this code

$session = Mage::getSingleton("core/session",  array("name"=>"frontend"));
echo $Value= $session->getData("user_id");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.