Integrate Yii With An Exsisting Application

This might be a question that has been asked numerous times. I’ve tried searching but either what I found didn’t answer my question or my search parameters are not specific enough. I’m still struggling with this a while now.

My problem;

I have a working website which consists of several php files which -in general- have the following structure:




include 'includes.php';  /* the current framework consisting of loads of functions */

include 'stdheader.php'; /* basic site layout, content folows....*/

original php code mixed with html /* the content */

include 'stdheader.php'; /* basic layout part 2 */


I’m looking for a way to replace the layout part by Yii and maintain (for now) the original content generation. This is a temporary situation, I’ll eventually migrate all scripts to Yii but I’d like to get the work so far live.

While reading the Wiki (View rendering flow), I got the idea of making a controller that replaces my stdheader.php by a call to Yii::createWebApplication($config)->run(); and use the output buffering to insert the original output back to the rendering flow somehow.

The idea isn’t complete yet, there is still a missing link but I feel that it might be a way to do it.

What I’m asking realy:

  • Is this a good way to go about integrating this?

  • If it’s a way to go, how do make the final step to integrate this

  • If it’s not the way to go, do you have other suggestions?

  • Will the Yii controller/action handling (r=controller/action) interfere with my other request (GET) variables?

Thanks for any suggestions or comment

For those who are interested; this is how I solved it.

I changed my ‘stdheader.php’ and ‘stdfooter.php’ to leave out all of my original site layout and only left in code that was required functionally, the files are almost empty now. There was some dynamic inclusion of CSS and JavaScript files which I moved those to an array (see code below).

I added all the legacy php files to the path that they were in (my project is a mess currenly, but that’s the price…) and (most of them) function again like they were but now I got them all within the layout that I defined in Yii.

My stdfooter now looks like this:


    .... /* old functional code */

    // get the output and save for handling

    $_SESSION['legacyContent'] = ob_get_clean();

    $_SESSION['legacyTitle']   = $legacyTitle;

    $_SESSION['legacyJs']      = $legacyJs;

    $_SESSION['legacyCss']     = $legacyCss;


    // change the following paths if necessary





The legacy config file is identical to the main config file except:




And the legacy controller then simply does a render:

    public function actionIndex()


        /* Add legacy JavaScripts & CSS files */

        foreach( $_SESSION['legacyJs'] as $js )




        foreach( $_SESSION['legacyCss'] as $css )





        $this->render('show', array('content'=>$_SESSION['legacyContent'], 'title'=>$_SESSION['legacyTitle']) );


And the view:


$this->pageTitle = $title;

echo $content;