Yii Framework Forum: Set Default Setting For Yii2 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Set Default Setting For Yii2

#1 User is offline   Dong Nguyen Huu 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 06-December 13

Posted 12 February 2014 - 10:32 PM

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
0

#2 User is offline   amnah 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 23-February 13

Posted 12 February 2014 - 11:56 PM

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.
0

#3 User is offline   Dong Nguyen Huu 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 06-December 13

Posted 13 February 2014 - 01:59 AM

Thanks amnah for quick reply
0

#4 User is offline   Pathfinder 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 19-January 13
  • Location:Ukraine

Posted 13 February 2014 - 02:46 AM

You can do this in the different ways:
1) set your custom handler for Application::EVENT_BEFORE_REQUEST or Application::EVENT_BEFORE_ACTION

2) you can create an application component with work you need in it's init() method. And adjust this component to be the preload one
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users