ログインページを実装しているのですが、セッションが切れてもログインページにリダイレクトされません。
$this->request->settion()->read('Auth.Users.name');
と記述し、確認するも、セッションが切れた場合、名前は空になり、homeに残ったままです。
何が原因なのでしょうか。
コード
PHP
1//UsersController.php 2 3 public function login(){ 4 $this->ViewBuilder()->layout('notauthtop'); 5 if($this->request->is('post')){ 6 $user = $this->Auth->identify(); 7 if($user){ 8 $this->Auth->setUser($user); 9 return $this->redirect('/home'); 10 } 11 $this->Flash->error('ユーザー名かパスワードが間違います'); 12 } 13 } 14 15 public function logout() 16 { 17 $this->request->session()->destroy(); 18 return $this->redirect($this->Auth->logout()); 19 } 20//Routes.php 21 //$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); 22 $routes->connect('/', ['controller' => 'Pages', 'action' => 'home']); 23 $routes->connect('/login', ['controller' => 'Users', 'action' => 'login']); 24 $routes->connect('/home', ['controller' => 'Pages', 'action' => 'home', 'home']); 25 26 /** 27 * ...and connect the rest of 'Pages' controller's URLs. 28 */ 29 //$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']); 30//AppController.php 31 $this->loadComponent('Auth',[ 32 'authenticate' => [ 33 'Form' => [ 34 'scope' => ['status' => '2'], 35 'fields' => [ 36 'username' => 'loginid', 37 'password' => 'password' 38 ] 39 ] 40 ], 41 'loginAction' => [ 42 'controller' => 'Users', 43 'action' => 'login' 44 ], 45 'logoutRedirect' => [ // ログアウト後に遷移するアクションを指定 46 'controller' => 'Users', 47 'action' => 'login', 48 ], 49 'authError' => '再度ログインしてください。', 50 'storage' => 'Session' 51 ]); 52 53//app.php 54 'Session' => [ 55 'defaults' => 'php', 56 'timeout' => 2,//単位は分 57 ], 58]; 59 60
他に何かするべきことってありましたでしょうか。