What are the downsides of the base controller in Zend?

I read somewhere that using the base controller is bad, and that there are lower sides than parties. This person said you should use plugins.

I need to get a request from the variable "lang" before each action and pass it to the current action. Now I made a basic controller with preDispatch, which receives it from the request and passes it through $this (any other controller leaves the database).

How do I implement it if I use plugins? And should I?

EDIT: Found a place where I read that base controllers are evil: Sending variables to a layout in Zend Framework is a comment on the last answer. Please note that my question is not like (I need to go to action, not the layout).

EDIT2: With your answers on how to implement, could you also explain why using a base controller is bad?

EDIT3: It seems it is not working. I did: created the helpers directory in the controllers folder, added to the Zend_Controller_Action_HelperBroker::addPath('../application/default/controllers/helpers/', 'Controller_Helper'); initializer Zend_Controller_Action_HelperBroker::addPath('../application/default/controllers/helpers/', 'Controller_Helper'); Created a file in this folder LangHelper.php and created the class Controller_Helper_Lang extends Zend_Controller_Action_Helper_Abstract . Why is it still not working? (maybe I need to add a request one or more times?)

EDIT4: I get:

Zend_Loader_PluginLoader_Exception: a plugin named 'Lang' was not found in the registry; paths used: Controller_Helper _: .. /application/default/controllers/helpers/;../application/admin/controllers/helpers/ Zend_Controller_Action_Helper_: Zend / Controller / Action / Helper / in C: \ wamp \ www \ EfCom \ library \ Zend \ Loader \ PluginLoader.php on line 412

+4
source share
1 answer

You should use Action Assistants rather than plugins.

That way, you could do, for example, $this->_helper->getLang() to get the Lang of your actions (with GetLang be your Action Helper), and not use the class attribute.

Plugins are useful for controlling request routing (for example, for adding ACL filtering). This is not what you want to do here.

Sample code for your assistant:

 class MyModule_Controller_Helper_GetLang extends Zend_Controller_Action_Helper_Abstract { /** * direct() is the default method called * when you use $this->_helper->getLang() */ public function direct() { $lang = /*get you lang here*/; return $lang; } } 

Tutorials:

I recommend putting your helpers in / application / controller / helpers. See Official Recommendation for catalog layout . They speak:

controllers / assistants . These directories will contain action assistants. Action assistants will be replaced with names like "Controller_Helper_" for the default module or "Controller_Helper" in other modules.

Update:
I used the base controller before I found out about the action helpers, which does the job, but lets say that there are helpers for this. This is a concept created specifically for what you want to do, with some advantages (for example, lazy loading, so that the helper only loads when you use it). Imagine that in a week you need to add another variable, but it is needed only on some pages, and not for everyone. With the base controller, these variables will be loaded every time. You must learn to do this correctly (with helpers) so that you can use it completely later. This will keep you updated on clean and organized. A controller is just a controller, an assistant is just an assistant .

+2
source

All Articles