Hello Yii开发人员:)
我是yii freamwork的新手,我想为我的模块建立一个独立的数据库,所以我在我的模块中创建了一个db配置,如下所示:
1-first我创建了返回db config
的db.php文件<?php
/**
* Created by PhpStorm.
* User: Rezvania
* Date: 3/10/2018
* Time: 11:31 AM
*/
return[
'class'=>'yii\db\Connection',
'dsn'=>'mysql:host=localhost;dbname=db_entry_mdu',
'username'=>'root',
'password'=>'',
'charset'=>'utf8',
'tablePrefix'=>'tbl_entry_mdu_'
];
2 - 所以我创建了修改我的模块配置的配置文件
<?php
/**
* Created by PhpStorm.
* User: Rezvania
* Date: 3/10/2018
* Time: 11:30 AM
*/
$db=require __DIR__.'/db.php';
return[
'defaultRoute'=>'entry',
'components'=>[
'db'=>$db,
]
];
3-finaly我在我的Module类中设置了
<?php
/**
* Created by PhpStorm.
* User: Rezvania
* Date: 3/10/2018
* Time: 11:26 AM
*/
namespace app\modules\entry;
use yii\base\Module;
use yii;
class EntryModule extends Module
{
public function init()
{
parent::init(); // TODO: Change the autogenerated stub
\Yii::configure($this,require __DIR__.'/config/config.php');
}
}
现在当我尝试使用表格数据时,我收到了这个错误:
该表不存在:
tbl_entry_mdu_user