【发布时间】:2014-04-29 01:52:27
【问题描述】:
我正在使用 Yii 框架和 PostgreSQL,我需要在非默认模式中创建新模型。我怎样才能做到这一点? 我尝试了以下方法:
protected/components/PgSchemaConnection.php
class PgSchemaConnection extends CDbConnection {
protected function initConnection($pdo)
{
parent::initConnection($pdo);
$stmt=$pdo->prepare("set search_path to master, public");
$stmt->execute();
}
}
protected/config/main.php
return array(
...
'db'=>array(
'connectionString' => 'pgsql:host=localhost;dbname=bsc',
'username' => 'aUser',
'password' => 'aPass',
'charset' => 'utf8',
'class' => 'PgSchemaConnection'
),
...
)
但是当我在控制台中运行时
>> model Foo
Warning: the table 'Foo' does not exist in the database.
generate models/relatedobjective.php
PHP Warning: Invalid argument supplied for foreach() in /home/cristhian/php_apps/yii-1.1.14.f0fee9/framework/cli/views/shell/model/fixture.php on line 13
PHP Warning: Invalid argument supplied for foreach() in /home/cristhian/php_apps/yii-1.1.14.f0fee9/framework/cli/views/shell/model/fixture.php on line 19
generate fixtures/relatedobjective.php
generate unit/relatedobjectiveTest.php
The following model classes are successfully generated:
relatedobjective
If you have a 'db' database connection, you can test these models now with:
$model=relatedobjective::model()->find();
print_r($model);
Yii 在数据库中没有找到 Foo 表(很奇怪,我已经创建了 Foo 表)
如何设置另一个架构?我做错了什么?
【问题讨论】:
标签: php postgresql yii database-schema