cakephp 3.0博客教程认证错误

时间:2015-04-04 07:21:36

标签: php cakephp-3.0

我是cakephp的新手..我已经直接从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 

有什么问题?是不是应该允许在没有身份验证的情况下添加用户?

2 个答案:

答案 0 :(得分:1)

如果您实施parent::initialize()方法,请务必在UsersController.php中致电public initialize()

答案 1 :(得分:1)

确保Auth Component文件中AppController.php已正确加载。