Home > Article > Backend Development > Simple implementation method of thinkphp3.x custom Action, Model and View, thinkphp3.xaction_PHP tutorial
This article describes the implementation method of thinkphp3.x custom Action, Model and View . 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"); } }
2. Create the default folder under xmall/tpl, create the Test folder under default, and create the test.html template file under Test;
3. Execute the URL: http://localhost/xmall/index.php/Test/index and the content of the test.html page will appear
4. Errors occurred during operation:
(1) The T in Test in the URL must be capitalized;
(2) Display does not need to provide the file extension, the default is index
5. Notes:
(1) To facilitate debugging,
should be added to the index.php entry filedefine("APP_DEBUG",true);
(2) 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"; } }
7. Add new method in xmall/Lib/Action/TestAction.class.php
public function test(){ $m=D("User"); echo $m->test(); }
8. Execution URL: http://localhost/xmall/index.php/Index/test, page output 123456
9. Note: The Model file name must be consistent with the name of the model, and is case-sensitive when calling;
Add 'URL_CASE_INSENSITIVE' =>true,//URL is not case sensitive in xmall/conf/config.php
PS: Here are several formatting and beautification tools recommended for this site. I believe everyone can use them in future development:
php code online formatting and beautification tool:
http://tools.jb51.net/code/phpformat
JavaScript code beautification/compression/formatting/encryption tool:
http://tools.jb51.net/code/jscompress
Online XML formatting/compression tool:
http://tools.jb51.net/code/xmlformat
SQL code online formatting and beautification tool:
http://tools.jb51.net/code/sqlcodeformat
Readers who are interested in more thinkPHP-related content can check out the special topics on this site: "ThinkPHP Getting Started Tutorial", "ThinkPHP Common Methods Summary", "Smarty Template Basic Tutorial" and "PHP Template Technology Summary".
I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.