YII2新建模块
来源:互联网 发布:2016网络效应试题答案 编辑:程序博客网 时间:2024/05/22 06:12
YII2支持多模块开发,需要在根目录下创建Modules文件夹
文件夹下包含需要创建的模块,如user,admin等
以user模块为例:
文件夹内包括controllers,models,views三个文件夹和一个UserModule模块类
该模块类继承自Module类,包含一个公共init方法,包含一些初始化代码并且可以自动加载。
在config/web.php文件,在$config数组中加入以下代码以配置该模块:
'modules' => array( 'user' => [ 'class' => 'app\modules\user\UserModule', ], ),
模块中的控制器,模型等均使用包含user的命名空间以正常使用。
例:
user模块下包含一个PublicController控制器,内容如下:
<?phpnamespace app\modules\user\controllers;use yii\web\Controller;use app\modules\user\models\User;class PublicController extends Controller{ public function actionIndex() { return $this->render('/public/index'); } }
在该模块views目录下包含一个public文件夹,里面包含一个index.php文件,内容如下:
<html><body>hello public/index</body></html>
通过http://servername/user/public/index即可访问,浏览器正常显示。
0 0
- YII2新建模块
- Yii2 新建页面介绍
- yii2:新建自己的layout
- yii2 elasticsearch模块代码
- Yii2 高级版 新建Api 应用
- Yii2 高级版新建一个 Api 应用
- Yii2.0框架基础--模块
- Yii2 应用结构之模块
- Yii2 中模块相关配置
- YII2.0多模块配置
- 新建模块报错
- opencms8.5.0-新建模块
- destoon新建模块
- ThinkPHP5新建一个模块
- ofbiz 新建模块
- DNN学习(新建模块)
- phpcms 新建模块并安装
- destoon 新建一个新模块
- 十四、自定义Jackson ObjectMapper把Long型转化为String类型
- effective javascript(四)——避免对于混合类型使用==运算符
- 坚持#第166天~心中有一个辛德勒不够好的信念,要珍惜缘分
- Spring配置FreeMarker
- Tensorflow基于linux环境python语言开发环境安装
- YII2新建模块
- Redhat7.0下 Apache Web服务的搭建与配置
- linux基础小知识
- sqlserver2014连接ODBC
- 自定义布局Dialog 自定义dialog右上角带叉号的dialog 点击右上角叉号关闭dialog
- 【精华版】mysql创建表(带外键)
- android中Surface View的用法
- HDU1176(DP)
- LeetCode 题解(Week 8): 523. Continuous Subarray Sum