Yii:这个夹具是如何被引用的?

时间:2011-05-21 17:11:12

标签: php unit-testing reference yii fixture

我正在Yii书中跟随并且在CH5(第101页)。在我们的单元测试中,我们定义了一个数组,用于指定要使用的夹具:

class ProjectTest extends CDbTestCase {
}
public $fixtures=array (
'projects'=>'Project', );

但是,fixtures文件是在'protected / tests / fixtures / tbl_project.php'中创建的,显然没有命名为'projects'。 Yii如何推断这一点?注意:我的数据库表名为tbl_project。

谢谢:)

1 个答案:

答案 0 :(得分:1)

您需要为数据库定义表前缀,然后再次创建模型。 如果您使用的是mysql(在'components'下的config> main.php中),这就是你的'db'定义的样子。

    'db'=>array(
        'connectionString' => 'mysql:host=localhost;dbname=test',
        'emulatePrepare' => true,
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
                    'tablePrefix'=>'tbl_',
    ),

一旦你有了前缀,yii应该能够为你的模型命名,不包括前缀。