This article takes YII 2.0.7 as an example to share with you about Yii multi-application and multi-module. Friends in need can refer to it
First look at multi-application and multi-module Features of the module:
Features of multiple applications:
Independent configuration file
Independent domain name
Features of multiple modules:
Unified configuration file
Unified domain name
So, how to actually decide whether to use multiple applications or multiple modules?
For the separation of front and backend, for example, the backend needs a separate domain name for management. This should use multiple applications.
The configuration of multiple applications is completely different. It is more convenient to use multiple applications. Use different configuration files
Multiple applications require more domain name configurations, which makes price comparison troublesome. For small projects, domain names are not distinguished. Multiple modules are better
The easiest way is to download the advanced application template of Yii2 from the official website: yii-advanced-app-2.0.12.tgz. After downloading and decompressing, enter the advanced
directory and run:
# Windows init.bat # Linux init
will open the web# of the two applications
frontend and
backend ##Directory generation entry file
index.php.
frontend and
backend represent frontend and background applications respectively. The directory structure inside is the same:
assets/ config/ controllers/ models/ runtime/ views/ web/
$ cd advanced/frontend/web $ php -S 0.0.0.0:8888 PHP 5.6.22 Development Server started at Sun Aug 20 21:10:28 2017 Listening on http://0.0.0.0:8888
common/models in the root directory.
http://www.yiichina.com/doc/g.... Example: Create a new h5 application in
frontend:
$ cd frontend $ mkdir -p modules/h5 && cd modules/h5 $ mkdir controllers $ touch Module.php
Module. php Content example:
<?php namespace frontend\modules\h5; class Module extends \yii\base\Module { public function init() { parent::init(); $this->params['foo'] = 'bar'; // ... 其他初始化代码 ... } }
frontend/config/main.php:
'modules' => [ 'h5' => [ 'class' => 'frontend\modules\h5\Module', // ... 模块其他配置 ... ], ],
modules/ h5/controllersNew controller class:
<?php namespace frontend\modules\h5\controllers; use Yii; use common\models\LoginForm; use frontend\models\SignupForm; use frontend\models\ContactForm; use yii\base\InvalidParamException; use yii\web\BadRequestHttpException; use yii\web\Controller; class SiteController extends Controller { public function actionIndex() { return "hello h5 module"; //return $this->render('index'); } }
http://localhost:8888/index.php?r=h5/site/index to access .
r=test/site/index. Just create a new subdirectory in the
frontend/controllers directory called
test, put the controller in it, and then change the namespace to
namespace frontend\controllers\test;
r=v1/site/index r=v2/site/index
http://www.cnblogs.com/52fhy/...
Related Recommended:Basic concepts of Yii2 configuration
Detailed explanation of Yii2.0 execution process
How to introduce the Yii framework
The above is the detailed content of Yii multi-application multi-module. For more information, please follow other related articles on the PHP Chinese website!