kakalos12
(Kakalos12)
1
Hi all,
I’m wondering how to set the default settings for application before any action of the controller is execute ?
For example, I want to change the timezone of the application based on the user settings, and I want to set them before the execution of any actions.
Any ideas ?
Thanks
amnah
(Jellysandwich5+1)
2
class SiteController extends Controller
{
public function beforeAction($action)
{
// do stuff
return parent::beforeAction($action);
}
}
You may want to consider creating a BaseController so you don’t need to repeat this function.
kakalos12
(Kakalos12)
3
Thanks amnah for quick reply
You can do this in the different ways:
-
set your custom handler for Application::EVENT_BEFORE_REQUEST or Application::EVENT_BEFORE_ACTION
-
you can create an application component with work you need in it’s init() method. And adjust this component to be the preload one