Wednesday, March 04, 2015

Running Any Codes Before Action on Controller Execute on Yii

You can execute any codes before action method on controller run with beforeAction() method. For example, you want to make every action method are JSON type on content. So, you can add method like this on your controller:

        protected function beforeAction($action){
            header('Content-Type: application/json');
            return parent::beforeAction($action);
        }

its will be effected to all actionAny() to JSON as type of content

No comments:

Post a Comment