A
A
Alexander Gerasimov2014-12-17 21:40:16
Yii
Alexander Gerasimov, 2014-12-17 21:40:16

Yii2 - is there an implementation of preController?

Hello toasters!
Prompt idea (idea, but not implementation). I'm sitting, I'm scratching my head a little - how is it right?
I am writing an application in Yii2 (advanced) . It would be desirable to organize something preController'a or something. For example, I store the language of the application in the database. Through the backend it is possible to change the default language. Writing 'language' => 'en-EN' in the config file is not very flexible. How then to use it? Put down the language everywhere? - Not!
So far, this is the only idea. Implement something like FrontendController that inherits from yii\web\Controller . In it in the init() methodall "read" and "set" (not only language, but also other options). Already further controllers inherit from FrontendController . Thus, I will already have the language that is registered in the database.
Connoisseurs of Yii, what is possible and what is more correct to come up with?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Zelenin, 2014-12-18
@agerasimov

Pavel Shorokhov is, of course, wrong. God classes are a bad pattern. Redefinitions should be made when they are needed.
But to hang the behavior on beforeRequest is what you need. https://github.com/yiisoft/yii2/blob/master/docs/g...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question