in onBeginRequest of the app, I have a SiteRouter that checks for ACTIVE/INACTIVE status of a site.
If INACTIVE, I need to redirect to the InActive message screen (site/inactive)
If ACTIVe, it continues to load (site/index)
if ($site->Status == "I") {
Yii::app()->request->redirect(Yii::app()->request->baseUrl.'/index.php/site/inactive');
}
It goes into infinite loop in the browser try to reach because it checks the same code each time every time it comes in.
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
It works! but it is still taking a little longer than any url if the site is active. The browser status shows "connecting…transferring…connecting…transferring" many times before it shows the correct page. If the checking is bypassed, any page will load instantly…
But error Handling throws a generic error page, how to throw a specific new SiteInactive error with its own layout and all? Not only this, I could have another "Site Under Construction" error with another layout as well
if($site->Status == "I"){
throw new CHttpException(404,'The specified post cannot be found.');
}
Is there a way to load and change different controllers at onBeginRequest and "render" (read: include) these different status page instead of a full redirect?
I think raising a CHttpException with status code 503 (Service Unavailable) should do it. And you can specify what the visitor will see in such cases by providing a view named "error503". See Displaying Errors in the guide.
I see the problem now, redirect calls "Yii::app()-end()" before the application is initialized ( onBeginRequest )
Use the same logic in CController::beforeAction($action) method, and there you can use the forward method ( $this->forward($url) ) instead of redirect, if you preffer not to change the url
in the site’s configuration file (default: protected/config/main.php) you can set the catchAllRequest to a path that should handle all incoming requests.
It does not need any additional checking, just a route:
…
‘catchAllRequest’ => array(‘site/inactive’),
…
in your SiteController class add a method ‘actionInactive’ which performs appropriate action like rendering some offline notice.