Home > Backend Development > PHP Tutorial > Simple implementation method of customizing Action, Model and View in thinkphp3.x

Simple implementation method of customizing Action, Model and View in thinkphp3.x

不言
Release: 2023-03-25 12:46:01
Original
1710 people have browsed it

This article mainly introduces the simple implementation method of thinkphp3.x custom Action, Model and View, and analyzes the specific steps and related implementation techniques of thinkPHP3. Friends can refer to

This article describes the implementation method of custom Action, Model and View in thinkphp3.x. Share it with everyone for your reference, the details are as follows:

1. Create the file TestAction.class.php in xmall/Lib/Action

class TestAction extends Action{
   function index(){
    $this->display("test");
   }
}
Copy after login

2. Create the default folder under xmall/tpl, create the Test folder under default, and create the test.html template file under Test;

3. Execution URL: http://localhost/xmall/ The content of the test.html page will appear in index.php/Test/index

4. Errors occurred during the operation:

(1) The T in Test in the URL should be capitalized;

(2) Display does not need to provide the file extension, the default is index

5, Note:

(1) To facilitate debugging,

define("APP_DEBUG",true);
Copy after login

(2) should be added to the index.php entry file It is best to specify the default template in the configuration file (xmall/Conf/config.php): 'DEFAULT_THEME' => 'default'

6. Create the file UserModel.class.php under xmall/lib/Model

class UserModel extends Model{
   function test(){
     return "123456";
   }
}
Copy after login

7. Add a new method in xmall/Lib/Action/TestAction.class.php

public function test(){
   $m=D("User");
   echo $m->test();
}
Copy after login

8. Execution URL: http://localhost/xmall/index.php/Index/test, page output 123456

9. Note: The Model file name must be the same as The name of the model is always case-sensitive when calling;

Add 'URL_CASE_INSENSITIVE' =>true,//URL is not in xmall/conf/config.php case sensitive

The above is the detailed content of Simple implementation method of customizing Action, Model and View in thinkphp3.x. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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