Is overriding AppController's beforeFilter() always recommended ?

Showing 1-4 of 4 messages
Is overriding AppController's beforeFilter() always recommended ? alaxos 12/11/12 1:02 PM
While answering a recent question on stackoverflow (http://
stackoverflow.com/questions/13825073/always-call-a-function-in-
cakephp), I discovered that it seems to be recommended in the cookbook
to always override the AppController beforeFilter() in child
controllers (http://book.cakephp.org/2.0/en/controllers.html#the-app-
controller), even if it is only to call the AppController's
beforeFilter() method like this:

public function beforeFilter() {
    parent::beforeFilter();
}

My feeling is that in OO programming, this is useless, because if we
don't override a method in a child class, the parent method is used.

I do know that when the beforeFilter() method is not overridden in
child controllers, the AppController's beforeFilter() is indeed
called, but as it is recommended in the cookbook, is there any
advantage to do so ? Am I missing something here ?
Re: Is overriding AppController's beforeFilter() always recommended ? euromark 12/11/12 2:31 PM
you can omit those methods if they dont do anything else except for calling the parent
the cookbook merely offers examples on how you would do it if you needed it

so yes, from an oop point of view, pretty useless
Re: Is overriding AppController's beforeFilter() always recommended ? cricket 12/11/12 2:56 PM
Is this what you're referring to?

"Please also remember to call AppController’s callbacks within child
controller callbacks for best results"

It's just saying to call the parent callback IF you include a callback
in your controller.
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups "CakePHP" group.
> To post to this group, send email to cake...@googlegroups.com.
> To unsubscribe from this group, send email to cake-php+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>
>
Re: Is overriding AppController's beforeFilter() always recommended ? alaxos 12/12/12 12:07 AM

Thanks for your answers. That's also how I understand this remark in the cookbook.

But it could probably be clarified, because apparently the given sample code may be a bit confusing for people not very confident with oop. It seems that it leads some people to include a beforeFilter() method in their child controllers even when it is not necessary.