我没有cakephp版本3的经验。1.3
我按照说明实现登录认证功能;http://book.cakephp.org/3.0/en/tutorials-and-examples/blog-auth-example/auth.html
我设法成功蛋糕烘焙我的cakephp v3.1.3应用程序。
我对UsersController有问题。php
我从中复制并粘贴了以下代码http://book.cakephp.org/3.0/en/tutorials-and-examples/blog-auth-example/auth.html;
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']);
} //public function beforeFilter(Event $event)
此代码的存在产生了以下错误;
Strict(2048):App\Controller\userscocontroller::beforeFilter()的声明应与App\Controller\AppController::beforeFilter(Cake\Event\Event$Event)[App/Controller\userscocontroller.php,第12行]代码上下文包括-App/Controller\userscocontroller]兼容。php,第12行Composer\Autoload\includeFile-ROOT\vendor\Composer\ClassLoader。php,第412行Composer\Autoload\ClassLoader::loadClass()-ROOT\vendor\Composer\ClassLoader。php,第301行spl_自动加载_调用-[内部],第??类_存在-[内部],行??Cake\Core\App::_classExistsInBase()-Core\src\Core\App。php,第89行Cake\Core\App::className()-Core\src\Core\App。php,第66行Cake\Routing\Filter\ControllerFactoryFilter::\u getController()-CORE\src\Routing\Filter\ControllerFactoryFilter。php,第81行Cake\Routing\Filter\ControllerFactoryFilter::beforeDispatch()-CORE\src\Routing\Filter\ControllerFactoryFilter。php,第49行Cake\Routing\DispatcherFilter::handle()-CORE\src\Routing\DispatcherFilter。php,第145行Cake\Event\EventManager::_callListener()-CORE\src\Event\EventManager。php,第389行Cake\Event\EventManager::dispatch()-CORE\src\Event\EventManager。php,第355行Cake\Routing\Dispatcher::dispatchEvent()-CORE\src\Event\EventDispatcherTrait。php,第78行Cake\Routing\Dispatcher::dispatch()-CORE\src\Routing\Dispatcher。php,第62行[main]-ROOT\webroot\index。第37行
如果删除有问题的代码段,错误就会消失。代码段有什么问题?
解决方案是在UsersC中添加以下行ontroller.php
use Cake\Event\Event;
蛋糕烘焙版没有上面这条线。
在蛋糕4.0.2草莓-现在是-
use Cake\Event\EventInterface;
public function beforeFilter(EventInterface $event)
{
parent::beforeFilter($event);
}