Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

Never do before, so just an idea

solution with few files in other dir

create a separate a demo dir and map it on your demo URL

In this dir put this index.php (may be your .htaccess too)

<?php
$yii=_PRODUCTION_PATH_.'/framework/yii.php';
$config_prod=_PRODUCTION_PATH_.'/protected/config/main.php';
$config_demo=dirname(__FILE__).'/demo_main.php';

require_once($yii);

$config = CMap::mergeArray($config_prod,$config_demo);

Yii::createWebApplication($config)->run();

the demo_main.php override the classes (user, db) to manage a better demo experience:

<?php
return array(
        'basePath'=>_PRODUCTION_DIR_.DIRECTORY_SEPARATOR.'..',
        'components'=>array(
             'user' => array(
                  // here you override the user class with a DEMO only user
                  'class'=>'DemoUser',
             )
        ),

solution with all files of prduction site in a different dir

Here follows the index.php in root dir

<?php

$yii='../framework/yii.php';

$configMain = include dirname(__FILE__).'/protected/config/main.php';
$configProd = include dirname(__FILE__).'/protected/config/production.php';
$configDemo = include dirname(__FILE__) . '/protected/config/demo.php';

require_once($yii);
// for the demo version
// instead of the comment can be an *if* or any solution to manage 2 configs
//$config = CMap::mergeArray($configMain,$configProd);
$config = CMap::mergeArray($configMain,$configDemo);

Yii::createWebApplication($config)->run();

demo.php is analogue to "demo_main.php" overridig classes and configs for the demo version of the site.

If I have understood well (according to the comment answers to original post) then There are several ways. Here is a link that I think can help great deal. It helped me set up and may be will help you! In Yii 2 it will be inherently supported

http://www.yiiframework.com/wiki/33/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top