我在登錄時訪問會話信息時遇到問題。我正在爲CakePHP使用Nice Auth插件。使用Nice Auth(CakePHP插件)設置會話並訪問會話信息。
我按照一些指令here
我所試圖做的是訪問用戶名稱,以便其他網頁,他們並不需要填寫他們是誰,當他們發送支持票上。
這是Userscontroller登錄功能:
public function login(){
if ($this->request->is('post') || ($this->request->is('get') && isset($this->request->query['openid_mode']))) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
}
else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
這是我會承擔我把
$this->Session->write('User.id', $userId);
下面是門票控制器:
public function send()
{
$userId = $this->Auth->user();
if (!empty($this->request->data))
{
$email = new CakeEmail();
$email->from(array('[email protected]'))
//->to($this->request->data['to'])
->to(array('[email protected]'))
->subject($this->request->data['subject']);
if ($email->send($this->request->data['message']))
{
$this->Session->setFlash(__('Email Sent Successfully'),
'default', array('class' => 'success'));
}
}
}
在那裏我會希望把這個代碼:
$userId = $this->Session->read('User.id');
然後在我的視圖顯示:
$userId = $session->read('User.id');
現在,我已經加入會話單元和助手的文件,我想那會是什麼造成了我的問題,但沒有骰子!
任何幫助,非常感謝。
我目前的錯誤信息是這樣的:
Notice (8): Undefined variable: session [APP/View/Tickets/send.ctp, line 10] Fatal error: Call to a member function read() on a non-object in /Users/bellis/workspace/cake/app/View/Tickets/send.ctp on line 10