zoukankan      html  css  js  c++  java
  • YII框架的模块化技术

    一、模块的创建

    利用yii的自动生成工具gii生成模块。

    1、访问:lcoalhost/web/index.php?r=gii

    2、点击 Module Generator 下面的 start

    3、填写 Module Class 例如:appmodulesarticleArticle

    解释:appmodules模块名称模块入口名称

    4、填写 Module ID 例如:Article

    解释:模块唯一id,一般与模块入口名称相同。

    5、点击 Preview

    6、点击 Generate 后得到如下代码

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

    将它写入配置文件。

    自动生成的代码,在网站根目录下的modules里面。

    二、模块的使用

    1、被其它模块调用

    <?php
    namespace appcontrollers; 
    use yiiwebController; 
    use YII; 
    class TestController extends Controller 
    {
        public function actionIndex() { 
            //获取子模块
            $article = YII::$app->getModule('article'); //参数是模块的id
            //调用子模块的操作
            $article->runAction('default/index'); //参数是 控制器/操作
        }
    }
    

    2、直接访问模块

    例如:http://www.testyii.com/web/index.php?r=article/default/index

    解释:localhost/web/index.php?r=模块ID/控制器名/操作名

  • 相关阅读:
    HDU 4913 Least common multiple
    HDU 4915 Parenthese sequence
    HDU 2459 Maximum repetition substring
    HDU 5727 Necklace
    HDU 5724 Chess
    HDU 5726 GCD
    hihoCoder1033 交错和 数位DP
    2016百度之星资格赛题解
    10LaTeX学习系列之---Latex的文档结构
    09LaTeX学习系列之---Latex 字体的设置
  • 原文地址:https://www.cnblogs.com/buexplain/p/4856256.html
Copyright © 2011-2022 走看看