cakephp 2.0 - How can I use Sessions and Auth cross controller? -
i have 2 controllers need communicate orderscontroller , userscontroller, because when new user places order process register form on order send userscontroller::register().
my register action uses auth log in user after basket processed returns fatal error: call member function login() on non-object:
//userscontroller::register($data = null) if(!empty($data)) $this->request->data['user'] = $data; if ($this->user->save($this->request->data)) { $registereduser = $this->user->read(null, $this->user->id); if ($this->auth->login($registereduser['user'])) if (empty($data)) $this->redirect($this->auth->redirect()); else return $this->user->id; }
i use action on normal registration page , other apis google or facebook inside userscontroller calling $this->register($data) , workes fine. when use in orderscontroller like:
//userscontroller::__construct() public function __construct($request = null, $response = null, $session = null) { parent::__construct($request, $response); if (isset($session)) $this->session = $session; }
i had override __construct because had same problem setflash()
//orderscontroller::add(); $newuser = new userscontroller(null, null, $this->session); $newuserid = $newuser->register($data['user']);
Comments
Post a Comment