thinphp namespace, the connection database is the configuration file to be modified, the model data models layer, the cross-controller call, how to obtain system constant information,

Source: Internet
Author: User

A namespace (mainly for automatic load classes)

* Namespace (equivalent to a virtual directory), in order for the class to have a unified folder to manage (can automatically load ' class '), each file must have a namespace
*TP How to make namespaces:
The *TP framework has an initial namespace (equivalent to the root directory) Thinkphp\libray
* There are also many root namespaces under the initial namespace, which are divided into two main categories:
Root in 1.TP core class (System file)
Under Libray, there are several folders with several roots (all folders are root)
2.APP inside the root (customization file)
The root of the app is named after the module name
Libray folder and the app inside the module folder are virtual in a root folder, this folder is equivalent to "\" (Root)

Second, obtain system constant information

Three, cross-controller call (in one (MainController.class.php) controller call another (logincontroller,class.php) controller inside the method)

1. Build two controllers

Main controller

Login Controller

3 Methods of invocation

three methods show the same result:

2.U method: The full path to the build method
echo U ("module/controller/method (login)");

3. If the cross-module call: $m = A ("Module folder name (e.g. Home)/login"); $m, method name ();

Iv. connecting database configuration and model data layer

1. If you connect to the database, first modify the database configuration: Open the thinkphp file under the Conf under the convention.php file, in this configuration file will need to modify the database configuration data copied to the configuration file you want to use,

Change the field cache to false in information

2. Make model models: the model itself is a class file, each table in the database corresponds to a model file (if there is no special requirement, the file can not be built)

Create a new model class file that corresponds to the Nation table:

To open the Model file, you can copy some of the required table personalization settings from the library\think\model.class.php file:

The personalization of tables copied from the model parent file can be placed in the model file of the built table:

Instantiating a Model object

thinphp namespace, the connection database is the configuration file to be modified, the model data models layer, the cross-controller call, how to obtain system constant information,

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.