I have referred to the documentation here:
http://book.cakephp.org/3.0/en/controllers.html
I am trying to put in beforeFilter into my AppController.php
public function beforeFilter(Event $event) {
}
I am getting an error however:
Strict (2048): Declaration of App\Controller\AppController::beforeFilter() should be compatible with Cake\Controller\Controller::beforeFilter(Cake\Event\Event $event) [APP/Controller/AppController.php, line 27]
Not sure if this is a bug, or if I am missing something?
I have tried:
public function beforeFilter(Cake\Event\Event $event) {
}
As well, but get the same issue.
Thanks again.
remember to put
use Cake\Event\Event;
In the list of uses at the beginning of the file!
Thanks @lorenzo :)
Sorry @lorenzo - just one other thing I noticed on this.
I have added use Cake\Event\Event; at the top of my AppController.
But now it seems that I need to call it again if I want to use beforeFilter in say my UsersController.php
If it is called in AppController.php, why does it still need to be called in other controller files?
use statements only live in the file, so you will need to repeat them in all files you use the class. That's just how php works
Thanks It works:
use Cake\Event\Event;
Thanks for it:
use Cake\Event\Event;
I'm already a little tired of the amount of files I have to explicitly use in V3.x compared to previous versions. I thought one of the points of conventions over configuration was that we wouldn't have to use these types of explicit import statements. Is there a significant performance gain to not lazy loading these files?
Is there a significant performance gain to not lazy loading these files?
We can't lazy load the files, as the autoloaders can't find them. One possible option could be to globally namespace commonly used classes, but we can't do that with every class in CakePHP as there are lots of conflicts. I'm not sure having an inconsistent convention is better than the present state.
Thanks
If use Cake\Event\Event; is not enough, don't forget to add parameter in function beforeFilter:
public function beforeFilter(Event $event) {
/* YOUR CODE */
}
@gaultierlecaillon ready, ty..!
@gaultierlecaillon Thanks !
I know this is i kinda old, but THANK YOU!
Most helpful comment
If use Cake\Event\Event; is not enough, don't forget to add parameter in function beforeFilter:
public function beforeFilter(Event $event) {
/* YOUR CODE */
}