Modules and controllers of thinkPHP5.0 framework

1. Module (take the front desk as an example)

1. Module address
                        C:\AppServ\www\tp5\application\index

 2. Function:
                        All front-end related aspects of the website are related to it

 3. New background module

        a. Create a new admin directory in the application directory (C:\AppServ\www\tp5\application)
                   b. Create a new model, view and controller in the admin directory
                   c. Create a new Index controller (Index.php) in the Controller directory

        d. Write code in Index.php
                   //declare namespace
                          namespace app\admin\controller;
                 //declare controller
                          class Index{                                 public function index(){                                 return "I am the background controller";                                }                           }



        e. Visit
                              http://www.tp.com/index.php/Admin/Index/index through the address bar

 

2. Controller

   1. Controller directory
                        C:\AppServ\www\tp5\application\index\controller

    2. Function:
                        write business logic

    3. Create a new controller (take the foreground as an example)

        a. Create a new User.php under the foreground controller directory (C:\AppServ\www\tp5\application\index\controller)

        b. You can write code in the controller
                         <?php 
                         // Declare the namespace
                               namespace app\index\controller;
                         // Declare the controller
                               class User{                          // index method                                 public function index(){                                        return "I am the front-end User controller The index method in ";                                   }                             }                        c. Visit                                  http://www.tp.com/index.php/Index/user/index in the address bar






      Note:
                       1. The file name of the controller must be capitalized

               2. The namespace must be declared in the control

               3. The class name in the controller must be consistent with the file name

*****************************************************************************************************

Controllers and modules are the most critical items in the framework of thinkPHP5.0.

Guess you like

Origin blog.csdn.net/qq_43269730/article/details/99884123