Home > PHP Framework > YII > body text

Where is the yii add module?

(*-*)浩
Release: 2019-11-06 09:04:03
Original
2825 people have browsed it

This article takes the Yii2 basic application template as an example to introduce the process of adding new modules to the framework:

Where is the yii add module?

##1. Create new module-related directories and files

step 1: Create a new directory structure (Recommended learning: yii tutorial)

First create a new modules directory in the root directory, and then add the module directory below this directory. Assuming that we need to add a user module here, we can name the directory user, and then add three directories, models, views, and controllers, under the user directory. As shown below:

Where is the yii add module?

step 2: Add module class file

Take adding user module as an example, we This class file can be ordered as UserModule.php. Note that this class needs to inherit yii\base\Module 

<?php
namespace app\modules\user;

use yii\base\Module;

class UserModule extends Module
{
}
Copy after login

2. The configuration module

is mainly in config/ Add relevant configurations to web.php. The configuration information is as follows:

&#39;modules&#39;=>array(
        &#39;user&#39;=>[
            &#39;class&#39;=>&#39;app\modules\user\UserModule&#39;,
        ]
    ),
Copy after login

3. You can add corresponding files to the models, views and controllers of the newly created user module. My example is as follows. After the creation is successful, You can enter http://localhost/user/register/index and the test runs successfully.

Where is the yii add module?

The above is the detailed content of Where is the yii add module?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
yii
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template