I'm currently writing an app as a plugin to wordpress and hence I need some unconventional solutions..
Currently my problem is that when Yii gets an error it throws the error at its error handler and then it exits PHP execution. Shouldn't there be a way to sandbox Yii to make it only quit it's own execution and let the external code continue?
In my case most of the page goes blank and none of the wordpress theme gets loaded.. So it becomes pretty hacky to design good error pages. (When everything goes ok, wordpress loads in Yii in the_content(); and it blends in with the wordpress theme.)
Any ideas?
You'll probably want to end up overriding the default Yii error / exception handlers to put in custom ones. If you take a look at my article about integrating Yii/Wordpress, there is an example of an expection handler override. Adapt that to your use and you should be fine.
Adjusting the site/error handler is not going to end up working well for you, as that tends to throw a 400 error header that you can't stop even if you render a different page. Ran into that the hard way while integrating Yii and Wordpress, as I tried that first.
Let us know if you get it going, would love to have better example code for melding Yii on as a plugin.
End Yii, with proper cleanup and without exiting the request. As shown on http://www.yiiframework.com/doc/api/1.1/CApplication#end-detail, it is done like so.
Yii::app()->end(0, false);
You have two options:
try catch
every single location where is possible to get exceptionYii allows using a controller action to handle the error display work. To do so, we should configure the error handler in the application configuration as follows:
return array(
......
'components'=>array(
'errorHandler'=>array(
'errorAction'=>'site/error',
),
),
);
In the above, we configure the CErrorHandler::errorAction property to be the route site/error which refers to the error action in SiteController. We may use a different route if needed.
public function actionError()
{
if($error=Yii::app()->errorHandler->error)
$this->render('error', $error);
}
You has ability to customize the route as well as the view's theme when you are working with WordPress