🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 创建一个新的模块 ## 创建modules步骤 1. GII ![](./img/2018-11-19_171813.png) 2. 配置文件 D:\wamp\www\weike.test\weiketest\protected\config\common.php ``` 'modules'=>array( ... 'courseCenter'=>array( 'class'=>'application.modules.courseCenter.CourseCenterModule', ) ... ); ``` 3. 控制器 D:\wamp\www\weike.test\weiketest\protected\modules\courseCenter\controllers\DefaultController.php 创建 actionIndex() 方法; 4. 访问路径 http://weike.test/index.php?r=courseCenter/default/index ## 创建models步骤 1. GII ![](./img/2018-11-19_173048.png) > 对于子目录或分库的表,使用点语法 2. 创建成功 D:\wamp\www\weike.test\weiketest\protected\models\wkxuetang\wkxtCourse.php ``` <?php class wkxtCourse extends CActiveRecord { public static function model($className=__CLASS__) { return parent::model($className); } ... public function tableName() { return 'wkxuetang.tbCourse'; } ... } ``` 3. 配置模块配置文件 **D:\wamp\www\weike.test\weiketest\protected\modules\courseCenter\CourseCenterModule.php** ``` <?php class CourseCenterModule extends CWebModule { public function init() { ... $this->setImport(array( 'courseCenter.models.*', 'courseCenter.components.*', 'application.models.wkxuetang.*', //导入模型 )); ... } ```