1.先配置好数据库
位置在common/config/main-local.php
更改如下:<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=name',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
];
1.搭建模型层
在模块名文件下的model下创建
模块名/model/数据库名.php
代码如下:
<?php
namespace app\models;//所有的model都要继承这个