I am not experienced with cakephp ver3.1.3
I followed the instructions to implement login authentication function; http://book.cakephp.org/3.0/en/tutorials-and-examples/blog-auth-example/auth.html
I managed to successfully cake bake my cakephp v3.1.3 app.
I have a problem with UsersController.php
I have the following code copied and pasted from 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)
The presence of this code created the error below;
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
If I remove the offending code segment, the error disappears. What is wrong with the code segment?
The solution is to add the following line to UsersController.php
use Cake\Event\Event;
The cake baked version does not have the above line.
On Cake 4.0.2 Strawberry - it is now -
use Cake\Event\EventInterface;
public function beforeFilter(EventInterface $event)
{
parent::beforeFilter($event);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With