Search code examples
phpyiidemo

Yii: Creating a Demo Site Without Replicating the Code Base


I need to set up a demo site for users to try a web app before signing up. The demo would be based on production code, however, it would require minor code changes: connection to a demo database, automatic creation/login of a new guest account for each user, etc.

The obvious solution is to replicate my code base as a second demo website and edit as necessary. Keeping the demo code in sync with production code is easy enough by adding a branch in subversion. I'm less than thrilled, however, at the prospect of having to do two updates on my server (production and then demo) every time I push code from development to production.

Initially I thought I might be able to replicate the website through a module. It's unclear if this is possible, however.

Is there a mechanic in Yii to execute an altered version of a website (config file and selected controllers)?


Solution

  • The testdrive demo app is configured for this - after you install, note the separate index-test.php, and protected/config/test.php.

    Unlike @IvanButtinoni's suggestion, you'll need to access index-test.php, instead of index.php, so you may need to modify your .htaccess if you're using clean URLs to allow access to index-test.php.

    When I do this, I usually write a custom init in the base controller.php:

        public function init() {
                // use test layout if using test config
                if (isset(Yii::app()->params['test'])) {
                        $this->layout='//layouts/test';
                }
                parent::init();
        }
    

    Obviously, I have a test parameter in my test.php . . .

    The only difference in my two layouts is that one sets the background color to be a bright yellow, just so it's very clear you're on a test site.