在main-local.php文件中加入如下代碼來配置模塊php
# 判斷在開發模式下開啓GII和debug工具 if (!YII_ENV_TEST) { // 開發環境debug工具 $config['bootstrap'][] = 'debug'; $config['modules']['debug'] = 'yii\debug\Module'; // GII 管理工具 $config['bootstrap'][] = 'gii'; $config['modules']['gii'] = 'yii\gii\Module'; }
# 瀏覽器輸入gii地址,打開gii工具 http://127.0.0.1/index.php?r=/gii/module
建立模塊:web
# 在配置文件中加入新建模塊的配置 'modules' => [ // 支付模塊 'payment' => [ 'class' => 'app\modules\payment\Payment', ], ], # 默認模塊路徑:\frontend\modules\payment\controllers\DefaultController.php namespace app\modules\payment\controllers; use yii\web\Controller; class DefaultController extends Controller { public function actionIndex() { echo '我是模塊payment'; exit; // return $this->render('index'); } }
# 控制器調用(在任意控制器加入如下代碼) $payment = yii::$app->getModule('payment'); $payment->runAction('default/index'); // 執行默認控制器中的index方法 # 瀏覽器直接訪問模塊 http://127.0.0.1/index.php?r=/payment/default/index
最後感言
兄弟們看了若是有問題,歡迎 留言或者QQ聯繫我,你們一塊兒交流學習 QQ:418250505bootstrap