Is it good to have a BaseController and force all controllers to extend this class?

I need some general behavior in all controllers. Is it good to have a BaseController and force all controllers to extend this class? If so, what is the correct way to avoid the Fatal error: Class 'BaseController' not found .

+1
source share
4 answers

This is certainly a general approach.

But Matthew Weyer O'Finney's ZF project draft article article explains how action-helpers can provide the same benefits with more flexibility.

In particular, a common base controller often becomes a dump for functionality that is used in controllers with several, but not all, so it becomes redundant. Action-helpers are an alternative to lazy workloads, invoking functionality just when and where you need it.

In addition, the hooks of the assistant action dispatcher - init() , preDispatch() and postDispatch() - allow you to automate plug-in functionality based on each controller.

I would become an assistant action. But, like most things, YMMV .; -)

+6
source

Yes, this is a good idea and a very common picture. Check out the "Subclass Action Controller" section of the ZF reference manual.

+3
source

No, do not do this. Use action assistants to add functionality to your controller. If you use a basic controller, it will quickly become complex and insecure. Action assistants provide more flexibility.

+3
source

Yes, that's a good idea.

What is the correct way to avoid Fatal error: Class 'BaseController' not found error.

You read more about Zend_Loader to avoid this error.

+2
source

Source: https://habr.com/ru/post/1388344/


All Articles