所有代碼在一個控制器中如何在cakephp 3.0中刪除會話?
我的代碼是這樣的。
public function login()
{
$session = $this->request->session();
$session_event_id = $session->read('Events.event_id');
$session_division_id = $session->read('Events.division_id');
if(!$session_event_id || !$session_division_id) {
$event_table = TableRegistry::get('Events');
$event = $event_table->find('all', ['fields' => ['id'], 'order' => 'id desc'])->first();
$session->write('Events.event_id', $event->id);
$session_event_id = $session->read('Events.event_id');
$division_table = TableRegistry::get('Divisions');
$division = $division_table->find('all',['fields' => ['id'], 'conditions' => ['event_id' => $event->id]])->first();
$session->write('Events.division_id', $division->id);
$session_division_id = $session->read('Events.division_id');
}
}
通過上面的代碼,我能夠寫入和讀取會話值,但同時註銷我想刪除這些會話數據
public function logout()
{
$session = $this->request->session();
$this->$session->delete();
return $this->redirect($this->Auth->logout());
}
Warning (4096): Object of class Cake\Network\Session could not be converted to string [APP/Controller/UsersController.php, line 56]
Notice (8): Object of class Cake\Network\Session to string conversion [APP/Controller/UsersController.php, line 56]
Error: Call to a member function delete() on a non-object File /var/www/html/MEX/src/Controller/UsersController.php
如果您收到錯誤,請即使它們非常基本,請始終發佈_complete_,_exact_錯誤消息,包括可能的堆棧跟蹤! – ndm
我已經明確提到可以退出的錯誤 –
注意在註銷時調用會話的delete()。你有'$ this - > $ session-> delete()'而不是'$ session-> delete()' – Eagle