A simple implementation method of thinkphp3.x custom action, model and view _php instance

Source: Internet
Author: User
Tags php template smarty template

This article describes the implementation of thinkphp3.x custom action, model and view. Share to everyone for your reference, specific as follows:

1, create the file in Xmall/lib/action TestAction.class.php

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, the implementation of Url:http://localhost/xmall/index.php/test/index will appear test.html page content

4, during the operation of the error occurred:

(1) The t of test in the URL should be capitalized;

(2) display does not need to provide file extensions, the default is index

5, Attention matters:

(1) In order to facilitate debugging, should be added in the index.php entry file

Define ("App_debug", true);

(2) It is best to specify a default template in the configuration file (xmall/conf/config.php): ' Default_theme ' => ' default '

6, create the file under Xmall/lib/model UserModel.class.php

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, the execution url:http://localhost/xmall/index.php/index/test, the page output 123456

9, note: Model filename to and model of the name has been, and in the call to distinguish case;

Add ' url_case_insensitive ' =>true,//url case-insensitive in xmall/conf/config.php

PS: Here recommend a few of the format of this site landscaping tools, I believe that we can use in future development:

PHP code online format Landscaping tools:
Http://tools.jb51.net/code/phpformat

JavaScript code Landscaping/compression/formatting/encryption Tools:
http://tools.jb51.net/code/jscompress

Online XML format/compression tools:
Http://tools.jb51.net/code/xmlformat

SQL code Online formatting Landscaping tools:
Http://tools.jb51.net/code/sqlcodeformat

More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Common Methods Summary", "Smarty Template Primer" and "PHP template technology Summary."

I hope this article will help you with the PHP program design based on thinkphp framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.