Simple implementation of thinkphp3.x custom Action, Model, and View, thinkphp3.xaction
This document describes how to implement thinkphp3.x custom actions, models, and views. We will share this with you 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 a ultultfolder under xmall/tpl, create a test folder under default, and create a test.html template file under test;
3. Run the URL: http: // localhost/xmall/index. php/Test/indexto display the content of the test.html page.
4. Errors During Operation:
(1) The T of Test in the URL should be capitalized;
(2) Display does not need to provide the file extension. The default value is index.
5. Notes:
(1) To facilitate debugging, add the index. php entry file
define("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 UserModel. class. php file under xmall/lib/Model.
class UserModel extends Model{ function test(){ return "123456"; }}
7. Add a new method in xmall/Lib/Action/TestAction. class. php.
public function test(){ $m=D("User"); echo $m->test();}
8. Run the URL: http: // localhost/xmall/index. php/Index/test. The page output is 123456.
9. Note: The name of the Model file must be the same as that of the model, and the Model name must be case sensitive during the time zone call;
Add 'url _ CASE_INSENSITIVE '=> true to xmall/conf/config. php. // The URL is case insensitive.
PS: We recommend several formatting and beautification tools on this site. I believe you can use them in future development:
Php code online formatting and beautification tools:
Http://tools.jb51.net/code/phpformat
JavaScript code beautification/compression/formatting/encryption tools:
Http://tools.jb51.net/code/jscompress
Online XML formatting/compression tools:
Http://tools.jb51.net/code/xmlformat
SQL code online formatting and beautification tools:
Http://tools.jb51.net/code/sqlcodeformat