【问题标题】:Yii: How is this fixture being referenced?Yii:这个夹具是如何被引用的?
【发布时间】:2011-08-30 07:21:31
【问题描述】:

我正在关注 Yii 的书,现在在 CH5(第 101 页)。在我们的单元测试中,它让我们定义一个数组来指定要使用的夹具:

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

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

谢谢:)

【问题讨论】:

    标签: php unit-testing reference yii fixture


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2016-10-12
      • 2012-04-10
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      相关资源
      最近更新 更多