thinkphp Framework Model

Source: Internet
Author: User

This article and everyone to share is mainly thinkphpFramework ModelRelated content, come together to look at it, hope to learn PHP to help you. 1in theMainController.class.phpthe controller has aTestmethod, and there is aDengthe method that I want inTestmethod is used in theDengMethodexpressed as <?phpnamespace home\controller;use think\controller;class Maincontroller extends controller{ Public Function test () { $this->deng (); } 2in theMainController.class.phpthe controller has aTestmethod, under the same template, there is another name namedIndexController.class.phpthe controller, which has aIndexmethod, I would like toTestmethod is used in theIndexmethod is expressed as: <?phpnamespace home\controller;use think\controller;class Maincontroller extends controller{ Public Function test () { //calling methods across controllers $index =new Indexcontroller (); $index->index (); $index =a ("index"); $index->index (); R ("Index/index"); }The above are three different calling methods 3in theHomefolder under theMainController.class.phpthe controller has aTestmethods, in different templatesAdminThe folder also has a name ofTextController.class.phpthe controller, which has aAAmethod, I would like toTestmethod is used in theAAmethod is expressed as: <?phpnamespace home\controller;use think\controller;class Maincontroller extends controller{ Public Function test () { //calling methods across modules $index =new \admin\controller\textcontroller (); $index->aa (); $index =a ("Admin/text"); $index->aa (); R ("Admin/text/aa"); } 4use the model to manipulate the database, using theDthe sub-class object is transferred, if theM("Nation"the parent object is transferred;Select ()all objects are a two-dimensional array, if theFind ()It's a piece of data, likeFind ("n001") $nation =d ("Nation"); $arr = $nation->select (); Var_dump ($arr); 5withwhereQuery StatementsWHERE (conditions) $nation =d ("Nation"); $arr = $nation->where ("code= ' n005 ' or code= ' n003 '")->select (); Var_dump ($arr)It's a two-piece data . 6 TABLE() can be used to switch data tablesI'm using a database.Clubthe table inCNAMEto switch $nation =d ("Nation"), $arr = $nation->table ("CNAME")->select (); Var_dump ("$arr"); 7 Field (One of the fields of the specified database),only the data from this field is queried . $nation =d ("Nation"), $arr = $nation->field ("code")->select (); Var_dump ($arr); 8 Order() refers to the order in which the contents of the query are arranged $nation =d ("Nation"); $arr = $nation->order ("Code desc")->select (); Var_dump ($arr); 9 Limit() paging queryIf there is only one value in (), it means how many data is displayed, and if there are two values (,) then it means how many bars are skipped. $nation =d ("Nation"); $arr = $nation->limit (6)->select (); Var_dump ($arr);If you are using thePage ()paging queries are more user-friendlypage (,)There are two values in parentheses, the first value represents the number of pages, and the second value indicates how many bars are displayed per page 10GroupingGroup ()like I'm going to checkCartable in accordance withBrandHow many data are grouped in each group $nation =d ("Nation"); $arr = $nation->field ("brand,count (*)")->table ("Car")->group ("brand")->select (); Var_dump ($arr); Joinmake two tables link up $login =d ("login"), $arr = $login->field ("Login.uid,login.pwd,cname.name")->join ("CNAME on cname.code= Login.code ")->select (); Var_dump ($arr);


Source: Blog Park

thinkphp Framework Model

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.