Yii Framework Forum: [Tutorial] Maintenance Of Each Controller - Yii Framework Forum

Jump to content

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

[Tutorial] Maintenance Of Each Controller [TUTORIAL] Maintenance of each controller Rate Topic: -----

#1 User is offline   John Aston 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 21-January 14

Posted 28 May 2014 - 05:03 AM

I had read an article about maintenance in Yii:
http://www.yiiframework.com/forum/index.php/topic/3975-maintenance-mode/

it's very nice, but the problem here is, I want SiteController still works but NewsController (PollController, ...) is maintenance, so how?
This my way, very simple. In file config/main.php:
'params'=>array(
    ....
    'maintenance' => array(
        // configure controller maintenance you want. True is maintenance, not exists or False is not maintenance
	'news' => true 
    )
)

Now, in file components/Controller.php
class Controller extends CController
{
   public function init()
   {
      $controllerID = Yii::app()->controller->id;

      if (isset(Yii::app()->params['maintenance'][$controllerID]) 
          && Yii::app()->params['maintenance'][$controllerID] == true) {
          //your code for maintenance
          Yii::app()->end();
      }
   }
}

This my way, hope can help you, tks for read my topic
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