gpt4 book ai didi

php - UsersController::beforeFilter() 的声明应该与 AppController::beforeFilter(Cake\Event\Event $event) 兼容

转载 作者:可可西里 更新时间:2023-11-01 12:41:59 33 4
gpt4 key购买 nike

我对 cakephp ver3.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): Declaration of App\Controller\UsersController::beforeFilter() should be compatible with App\Controller\AppController::beforeFilter(Cake\Event\Event $event) [APP/Controller\UsersController.php, line 12] Code Context include - APP/Controller\UsersController.php, line 12 Composer\Autoload\includeFile - ROOT\vendor\composer\ClassLoader.php, line 412 Composer\Autoload\ClassLoader::loadClass() - ROOT\vendor\composer\ClassLoader.php, line 301 spl_autoload_call - [internal], line ?? class_exists - [internal], line ?? Cake\Core\App::_classExistsInBase() - CORE\src\Core\App.php, line 89 Cake\Core\App::className() - CORE\src\Core\App.php, line 66 Cake\Routing\Filter\ControllerFactoryFilter::_getController() - CORE\src\Routing\Filter\ControllerFactoryFilter.php, line 81 Cake\Routing\Filter\ControllerFactoryFilter::beforeDispatch() - CORE\src\Routing\Filter\ControllerFactoryFilter.php, line 49 Cake\Routing\DispatcherFilter::handle() - CORE\src\Routing\DispatcherFilter.php, line 145 Cake\Event\EventManager::_callListener() - CORE\src\Event\EventManager.php, line 389 Cake\Event\EventManager::dispatch() - CORE\src\Event\EventManager.php, line 355 Cake\Routing\Dispatcher::dispatchEvent() - CORE\src\Event\EventDispatcherTrait.php, line 78 Cake\Routing\Dispatcher::dispatch() - CORE\src\Routing\Dispatcher.php, line 62 [main] - ROOT\webroot\index.php, line 37

如果我删除有问题的代码段,错误就会消失。代码段有什么问题?

最佳答案

解决方案是在 UsersController.php 中添加以下行

use Cake\Event\Event;

蛋糕烘焙版没有上面这行

关于php - UsersController::beforeFilter() 的声明应该与 AppController::beforeFilter(Cake\Event\Event $event) 兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32690756/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com