Yii:在不复制代码库的情况下创建演示站点

时间:2012-11-30 06:37:02

标签: php yii demo

我需要设置一个演示网站,供用户在注册前试用网络应用。该演示将基于生产代码,但是,它需要进行少量代码更改:连接到演示数据库,为每个用户自动创建/登录新的访客帐户等。

显而易见的解决方案是将我的代码库复制为第二个演示网站,并根据需要进行编辑。通过在subversion中添加分支,可以很容易地使演示代码与生产代码保持同步。然而,每次我将代码从开发推向生产时,我都不得不在我的服务器(生产和演示)上进行两次更新。

最初我以为我可以通过模块复制网站。然而,目前还不清楚这是否可能。

Yii是否有机械师执行网站的更改版本(配置文件和选定的控制器)?

3 个答案:

答案 0 :(得分:4)

永远不要做,所以只是一个想法

其他目录中包含少量文件的解决方案

创建一个单独的演示目录并将其映射到您的演示URL

在这个目录中放了这个index.php(也可能是你的.htaccess)

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

demo_main.php覆盖类(user,db)以管理更好的演示体验:

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

使用不同目录中的所有prduction网站文件的解决方案

以下是root dir中的index.php

<?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 类似于“demo_main.php”覆盖类和网站演示版本的配置。

答案 1 :(得分:2)

为此配置了testdrive demo app - 安装后,请注意单独的index-test.phpprotected/config/test.php

与@ IvanButtinoni的建议不同,您需要访问index-test.php,而不是index.php,因此如果您使用干净的网址来访问{{},则可能需要修改.htaccess 1}}。

当我这样做时,我通常会在base controller.php中编写一个自定义init:

index-test.php

显然,我的test.php中有一个测试参数。 。 。

我的两个布局的唯一区别是,将背景颜色设置为亮黄色,这样就非常清楚您是否在测试网站上。

答案 2 :(得分:1)

如果我理解得很好(根据对原帖的评论答案)那么有几种方法。这是一个我认为可以帮助很多的链接。它帮助我成立,可能会帮助你! 在Yii 2中,它将是inherently supported

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