Yii Framework Forum: Maintance page - Yii Framework Forum

Jump to content

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

Maintance page Rate Topic: -----

#1 User is offline   Speeedfire 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 182
  • Joined: 02-March 12

Posted 23 May 2012 - 03:05 PM

Hi,
i wanna to make a maintance page. But i have any probleme.

is it my init, from the Controller

        public function init() {
            $model = Maintance::model()->findByPk(1);
            if($model->aktiv == 1 && !Yii::app()->getModule('user')->isAdmin()) {
                if($this->id->action != 'maintance') {
                        Yii::app()->user->logout();
                        $this->redirect(array('/site/maintance'));
                }   
            }
        }


If i write to the if $this->action already drop error:
Trying to get property of non-object


Or is use $this->route, not write the action, only the controller.
0

#2 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,114
  • Joined: 05-January 12
  • Location:Morocco

Posted 23 May 2012 - 05:39 PM

what is this?
$this->id->action

Is it supposed to be this?
$this->getAction()->getId()

or
$this->action->id

1

#3 User is offline   Speeedfire 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 182
  • Joined: 02-March 12

Posted 24 May 2012 - 03:02 AM

 bennouna, on 23 May 2012 - 05:39 PM, said:

what is this?
$this->id->action

Is it supposed to be this?
$this->getAction()->getId()

or
$this->action->id




If i use $this->action->id, drop error.
Trying to get property of non-object

What is the best idea, for excluding login,maintance action? :rolleyes:
0

#4 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 24 May 2012 - 03:21 AM

$this->action is not available within init() because it was not created/initialized at that point.

You can use beforeAction():

public function beforeAction($action)
{
   // $action->id
}


Don't forget to return true if you don't redirect.
1

#5 User is offline   Speeedfire 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 182
  • Joined: 02-March 12

Posted 24 May 2012 - 03:42 AM

 Y!!, on 24 May 2012 - 03:21 AM, said:

$this->action is not available within init() because it was not created/initialized at that point.

You can use beforeAction():

public function beforeAction($action)
{
   // $action->id
}


Don't forget to return true if you don't redirect.


Thank you! Is it great! :)
0

#6 User is offline   Speeedfire 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 182
  • Joined: 02-March 12

Posted 25 May 2012 - 09:49 AM

I have a little probleme with the mainteance page.

I use 2 domain with 1 yii "motor".

The 1. domain is correct with this beforeaction, but the 2. domain is always drop, when i go to another controller/action. :(

        public function beforeAction($action) {
                $model = Maintance::model()->findByPk(1);
                if($model->aktiv == 1 && !Yii::app()->getModule('user')->isAdmin()) { 
                    if($this->id != 'admin' && $this->route != 'admin/login' && $action->id != 'maintance') {
                        Yii::app()->user->logout();
                        $this->redirect(array('/site/maintance'));
                    } else {
                        return true;
                    }
                } else {
                    return true;
                }
        }

0

#7 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 25 May 2012 - 09:56 AM

What you mean with "drop"? What exactly doesn't work on the domain #2?
0

#8 User is offline   Speeedfire 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 182
  • Joined: 02-March 12

Posted 25 May 2012 - 09:59 AM

 Y!!, on 25 May 2012 - 09:56 AM, said:

What you mean with "drop"? What exactly doesn't work on the domain #2?


The #2 always logged out, when i click to another controller/action.

Edit: Yii::app()->getModule('user')->isAdmin() show false, when is clicked.
0

#9 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 25 May 2012 - 10:04 AM

Maybe it has something to do with the session cookie? Are these 2 different domains or 1 domain + 1 subdomain?
0

#10 User is offline   redguy 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 585
  • Joined: 02-July 10
  • Location:Central Poland

Posted 25 May 2012 - 10:05 AM

Also - there is a 'catchAllRequests' config entry which does maintenance mode redirection, however by default you have to switch it on/off in config file: http://www.yiiframew...lRequest-detail
red
0

#11 User is offline   Speeedfire 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 182
  • Joined: 02-March 12

Posted 25 May 2012 - 10:11 AM

 Y!!, on 25 May 2012 - 10:04 AM, said:

Maybe it has something to do with the session cookie? Are these 2 different domains or 1 domain + 1 subdomain?


I use session, not cookies. 2 differend domains.
But i dont use the mainteace works fine the login in the 2 domain.

 redguy, on 25 May 2012 - 10:05 AM, said:

Also - there is a 'catchAllRequests' config entry which does maintenance mode redirection, however by default you have to switch it on/off in config file: http://www.yiiframew...lRequest-detail


Yes, but i use db to the on/off mainteance and not edit the file. And this beforeAction() allow to admin anyone in the page and deny all other.
0

#12 User is offline   Speeedfire 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 182
  • Joined: 02-March 12

Posted 25 May 2012 - 11:00 AM

I'm happy! :)

In the main i use this ->
'preload'=>array('log', 'user'),


It's works. Thanks for all. :)
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