It must be clear this time. thinkphp model, naming conventions between databases

Source: Internet
Author: User

ServiceSiteModel.class.php This model controls the database is the Service_site table;

1<?PHP2 namespace Admin\model;3  UseThink\model;4 classServicesitemodelextendsModel {5 6     Private $page= "";7 8     Private $countNum= "";9 Ten      Public functionGetList ($pagesize=25) {

When the data sheet is underlined , you must use the Hump method to name the thinkphp to know where your data table name is underlined,

When there is no underline, that is, when our database table name is: Servicesite, we can direct the model name as: ServicesiteModel.class.php

So in terms of the above: the first letter of the model is always capitalized; brother 、、、 as to the need to capitalize, look at your data sheet name

Among the controllers we Howe not hesitate to write such

1<?PHP2 namespace Admin\controller;3  UseThink\controller;4 classServiceControllerextendsCommoncontroller {5     //member List6      Public functionservice_list () {7         $s= D (' Service_site ');8         ###        

Well, forgive me, I've drilled niu Jiao jian here.

D(‘[项目://][分组/]模型‘,‘模型层名称‘)

(from the Development Manual):

The following naming conventions should be followed as far as possible during development with thinkphp:

  • class files are suffixed with . class.php (this refers to the class library file used internally by thinkphp, which does not represent the externally loaded class library file), is named with the Hump method , and the first letter is capitalized , e.g. DbMysql.class.php;
  • Ensure that file naming and invocation are case-sensitive, because the case sensitivity is on top of Unix-like systems (while thinkphp is checked for capitalization even on Windows platforms under debug mode);
  • The class name and file name are the same (including the same capitalization), for example, the file name of the Useraction class is UserAction.class.php, and the Infomodel class name is InfoModel.class.php, and the class name of different class library has certain specification;
  • Other class library files, such as functions, configuration files, and so on, are usually suffixed with. PHP (third party not required);
  • The name of the function uses lowercase letters and underscores, such as get_client_ip;
  • methods are named using the Hump method , and the first letter lowercase or use underscore "_", such as getusername,_parsetype, usually the method that begins with an underscore belongs to the private method;
  • Properties are named using the Hump method , and the first letter lowercase or use underscore "_", such as TableName, _instance, usually the underscore property belongs to the private property;
  • A function or method that begins with a double underscore "__" as a magical method , such as __call and __autoload;
  • constants are named with uppercase letters and underscores, such as Has_one and Many_to_many;
  • Configuration parameters are named with uppercase letters and underscores, such as html_cache_on;
  • Language variables are named in uppercase letters and underscores, such as My_lang, where a language variable that starts with an underscore is usually used for system language variables, such as _class_not_exist_;
  • There is no mandatory specification for the naming of variables, which can be carried out according to the team specification;
  • The thinkphp template file is suffixed with. html By default (can be modified by configuration);
  • data tables and fields are named in lowercase and underlined , and note that field names do not start with an underscore, such as the Think_user table and the User_name field, similar to _username Such data table fields may be filtered.

It must be clear this time. thinkphp model, naming conventions between databases

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.