ログイン時にセッション情報にアクセスできません。CakePHP のプラグインである Nice Auth を使用しています。
ここでいくつかの指示に従いました
私がやろうとしているのは、ユーザーのユーザー名にアクセスして、別のページでサポート チケットを送信するときに自分が誰であるかを記入する必要がないようにすることです。
これは、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('xxxx@example.com'))
//->to($this->request->data['to'])
->to(array('helpdesk@example.com'))
->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