Home > PHP Framework > ThinkPHP > body text

How to add module files in ThinkPHP

WBOY
Release: 2023-05-29 12:34:45
forward
986 people have browsed it

The structure of the ThinkPHP framework: the core file of the framework is the ThinkPHP folder, the application folder is Application, and the application configuration and running data are stored in the two subdirectories of Home and Admin under the folder. inside. Under the application folder, each subdirectory represents a module in the MVC structure. You can easily add a new module by just creating a new directory and configuring the corresponding files.

The following are the specific steps:

  1. Follow camel case casing rules and create a new module folder in the application folder. If you need to create a module named "News", you must create a new folder named "News" in the application folder.

  2. Inside the module folder, create a folder called "Controllers" and add the controller there. For example, if we want to add a controller file under the News module, we need to create a folder named "controller" under the News folder, and then create the corresponding controller file under the folder.

  3. Add a new configuration file in the configuration folder under the module folder. For example, to add a configuration file under the News module, you need to create a folder named "config" under the News folder, and then create the corresponding configuration file under the folder.

  4. Configure the corresponding configuration in the main configuration file to make the newly added module folder take effect. Add the following code to the public configuration file config.php, which is located within the application folder

'module' => array('News'), //多个模块用逗号分隔
Copy after login
  1. Finally, enter the corresponding URL in the browser to verify whether the newly added module has been successfully configured. We can add a new controller named "Index" in the News module and test it by accessing the following address

http://yourdomain/index.php/News/Index /index

In ThinkPHP, the three concepts of module, controller and operation method are very important. The module is the main module in the application, the controller is a functional module in the module, and the operation method is the control specific methods in the device. Therefore, when adding a new module file, it needs to be configured according to this structure.

The above is the detailed content of How to add module files in ThinkPHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!