zoukankan      html  css  js  c++  java
  • Yii2 模块module笔记

    包含内容:

    使用GII新建module

    建立子模块

    在其他控制器中调用模块的操作(action)

    1. 使用Gii工具新建module

    注意模块的路径,我们没有写backendmodulesArticle。多了一层article目录是为了防止如果有多个模块共用同一文件。

    2. 在backendconfigmain.php中添加配置代码。

      'modules' => [
            'article' => [
                'class' => 'backendmodulesarticleArticle',
            ],
        ],

    3. 访问

    http://你的项目后台地址/article/default/index

    4. 调用模块中的操作

    在后台某个控制器文件,如backendcontrollersCarController.php 中添加调用模块动作的代码

        public function actionIndex()
        {
    
            // 获取子模块
            $arcileModule = Yii::$app->getModule('article');
            // 调用子模块操作
            $arcileModule->runAction('default/index');
            ........

    5. 建立子模块。在article下新建留言comment模块

    Module Class填写:backendmodulesarticlemodulescommentComment

    6. 添加配置信息

    打开backendmodulesarticleArticle.php。在init方法内加入

        public function init()
        {
            parent::init();
    
            $this->modules = [  
                'comment' => [
                    'class' => 'backendmodulesarticlemodulescommentComment',
                ],
            ];
            // custom initialization code goes here
        }

    7. 访问

    http://你的项目后台地址/article/comment/default/index

    若要直接访问,http://你的项目后台地址/comment/default/index

    需要将刚才的配置信息加入到backendconfigmain.php下面的配置文件里

  • 相关阅读:
    AI进阶之路
    python--数学运算函数
    QT之QChar
    字符串类QString
    Qt5多线程
    matplotlib动画
    matplotlib的安装和允许中文及几种字体
    python---wav音频
    python---多线程
    python--Excel模块xlwings
  • 原文地址:https://www.cnblogs.com/mafeifan/p/4855437.html
Copyright © 2011-2022 走看看