ThinkPHP framework model and thinkphp framework model

Source: Internet
Author: User

ThinkPHP framework model and thinkphp framework model

1. The MainController. class. php controller has a test method and a deng method. I want to use the deng method in the test method.

Indicates

<?phpnamespace Home\Controller;use Think\Controller;class MainController extends controller{    public function test()    {       $this->deng();    }

2 In MainController. class. the php controller has a test method. In the same template, there is also a method named IndexController. class. php controller, which has an index method. I want to use the index method in the test method as follows:

<?PhpNamespace Home \ Controller; use Think \ Controller; class MainController extends controller {public function test () {// cross-Controller call method $ index = new IndexController (); $ index-> index (); $ index = A ("Index"); $ index-> index (); R ("Index/index ");}

The above are three different call methods.

3. MainController in the Home folder. class. the php controller has a test method, and there is a TextController named in the Admin folder of different templates. class. php controller, which has an aa method. I want to use the aa method in the test method as follows:

 

<? Phpnamespace Home \ Controller; use Think \ Controller; class MainController extends controller {public function test () {// cross-module call method $ index = new \ Admin \ Controller \ TextController (); $ index-> aa (); $ index = A ("Admin/Text"); $ index-> aa (); R ("Admin/Text/aa ");}

 

4. The model is used to operate the database. The Child class object is called by D. If M ("nation") is used to call out the parent class object, select () is used () all objects are called as a two-dimensional array. If find () is used to call a piece of data, such as find ("n001 ")

$nation=D("nation");
$arr=$nation->select();var_dump($arr);

5. Use the where query statement where (condition)

 $nation=D("nation");        $arr=$nation->where("code='n005' or code='n003'")->select();        var_dump($arr)

Two pieces of data are found.

6. TABLE () can be used to switch data tables. I chose the TABLE cname in the database club to switch data tables.

$nation=D("nation");$arr=$nation->table("cname")->select();var_dump("$arr");

7 field (a field in the specified database), only the data of this field is queried.

$nation=D("nation");$arr=$nation->field("code")->select();var_dump($arr);

8 order () refers to sorting the query Content in order

 $nation=D("nation");$arr=$nation->order("code desc")->select();        var_dump($arr);

9 limit () Paging query if there is only one value in (), it means how much data is displayed. If there are two values (,), it means how many lines are skipped and how many lines are displayed.

$nation=D("nation");$arr=$nation->limit(6)->select();        var_dump($arr);

If the page () Paging query is used, there will be two values in the page (,) brackets. The first value indicates the page number, and the second value indicates the number of entries displayed on each page.

10 group () for example, I want to check the number of data entries in each group by brand in the car table.

$nation=D("nation");$arr=$nation->field("brand,count(*)")->table("car")->group("brand")->select();
var_dump($arr);

11 join: Associate two tables

 

$login=D("login");$arr=$login->field("login.uid,login.pwd,cname.name")->join("cname on cname.code=login.code")->select();var_dump($arr);

 

 

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.