我是一個新手,CakePHP的..我直接從3.0CakePHP的3.0博客教程認證錯誤
啓動它,我也跟着教程BLOG 1,2和現在所面臨的博客教程錯誤 - Authentication and Authorization
// src/Controller/UsersController.php
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
// Allow users to register and logout.
// You should not add the "login" action to allow list. Doing so would
// cause problems with normal functioning of AuthComponent.
$this->Auth->allow(['add', 'logout']);
}
當我嘗試訪問/ users/add頁面時出現錯誤。
Error: Call to a member function allow() on a non-object
File : src\Controller\UsersController.php
出了什麼問題?它不應該允許添加用戶沒有身份驗證?
您是否在'AppController'中添加了'auth'作爲組件? – 2015-04-04 07:28:11
本教程中的這一部分:'認證(登錄和註銷)'http://book.cakephp.org/3.0/en/tutorials-and-examples/blog-auth-example/auth.html – 2015-04-04 07:31:09
是的存在'公共函數初始化() { $ this-> loadComponent('Flash'); $這 - > loadComponent( '驗證',[ 'loginRedirect'=> [ '控制器'=> '文章', '動作'=> '索引' ], 'logoutRedirect'=> [ ' controller'=>'Pages', 'action'=>'display', 'home' ] ]); }' – 2015-04-04 07:42:24