Yii, how do I end Yii app execution without ending PHP script execution

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?

Solutions

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.

You have two options:

  1. You have to do try catch every single location where is possible to get exception
  2. Handling the error, then once exception came up, it would redirect all your app to a desired beauty error page (with Wordpress theme)

Yii 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

Yii handling error details

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);

Similar questions

htaccess rule to avoid duplicates ending with index.php
I have page duplicates with ending /index.php Examples: domain.com/ domain.com/index.php - duplicated domain.com/about domain.com/about/index.php - duplicated domain.com/blog/article domain.com/blog/article/index.php - duplicated Site is based on WordPress and currently there is such rules: What rule should I add to make all pages ending with index...
Reusing header.php from Yii application
I'm building a website that uses Wordpress as the CMS and is built with Yii framework. All the business logic works fine. Most visible pages are filled with content from Wordpress admin and only the user profile section is built with Yii. My problem is that I would like to reuse the layout of the wordpress pages in the Yii app. Initially I tried to...
yii.php: failed to open stream: No such file or directory
I'm trying to install a live wordpress site locally on my Ubuntu machine. Everything is working ok except for a portion of the site which I believe is built on the YII framework. When I point the browser to http://localhost.000-wordpress.co/app I get the below error in my apache2 error log: Any idea what I should do, I FTP'd the entire site down fr...
How do I bolt a Wordpress blog onto a /blog URL for a PHP Yii site running on Heroku?
I'm thinking of modifying the .htaccess file to create a reverse proxy, or to forward requests in Yii, but I'm not sure. It might be similar to this answer, but for PHP instead of Rails. How can I use a subdirectory instead of a subdomain? Is there a standard Composer plugin for PHP/Yii for setting up a reverse-proxy?
Wordpress Install - "end of script output before headers" when running simple php script
I have a multi-site Wordpress installation for a client, and for one of the forms I need to do some manual database interaction as the feature is separate. The problem I'm having however, is that any simple PHP script I uploaded to anywhere on the site is throwing an "end of script output before headers" error according to the logs. The script is l...
Allow the execution of an external PHP script for logged users
I need to call a PHP script external to WP and I would like to take advantage of the credentials of WP so that only logged users can access this script. I have tried to use this code embedded in my external PHP script but it would not work (where XXX is the domain name): Do you have any clue? Many thanks in advance!!

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .