Well. thinkphp01

Source: Internet
Author: User
Document directory
  • Use m METHOD
  • Use method D

Seeing the official documentation, I think my head is very big. It's very big. It's huge. The planet is so big...

Okay, I'm a mentally retarded child.

I like the Quick Start of this order.

Http://www.5idev.com/thinkphp

Okay.

The action is written in the Action directory under the automatically generated Lib. it is implemented by inheriting action, where multiple public methods can be written. then you can use http: // localhost/demo/index. PHP/news/index is accessed in a strange way. news is the name of the action, which must be named newsaction. class. PHP, and there is an index method. (I started to write http: // localhost/demo/news/index. I thought it was the same as Zend .)

Oh, there is also the downloaded phped5.9. it's quite powerful, but some operations need to be adapted.

 

Http: // 127.0.0.1/html/MyApp/index. php/module/Operation

Http: // 127.0.0.1/html/MyApp/index. php/M/module/A/Operation

Smart pathinfo format. It seems to be supported.

 

 

The project configuration directory conf contains a config. php file, which is the thinkphp system configuration file.

See it all by yourself

<? PHP
If (! Defined ('Think _ path') Exit ();
Return array (
   
// 'Config maps'  
=> 'Configuration value'
   
'Db _ type'  
=> 'Mysql ',
   
// Database type used
   
'Db _ host'  
=> 'Localhost ',
   
'Db _ name'  
=> 'Test ',
   // Database Name
   
'Db _ user'  
=> 'Root ',
   
// Access the database account
   
'Db _ pwd'   
=>
'',     
// Access the Database Password
   
'Db _ port'  
=> '123 ',
   
'Db _ prefix'=> 'Dev _',
   // Table prefix
   
'App _ debug'=> True,
   
// Debug mode switch
   
'Token _ on' =>
True,  
// Enable token Verification
   
'Url _ model'=> 1,
   
// URL mode: 0 Normal Mode 1 pathinfo 2 rewrite 3 compatible mode
);
?>
Other settings

'Url _ pathinfo_depr'  
=> '/', // The separator between parameters in pathinfo URL Mode
'Default _ theme'      
=> 'Default', // default template topic
'Url _ html_suffix'    
=> '.Html ',// URL pseudo-static suffix settings
'Default _ charset'    
=>
'Utf-8 ',   
// Default output Encoding
'Default _ timezone'   
=> 'Prc', // Default Time Zone
'Default _ ajax_return'=>
'Json ',    
// Default Ajax data return format, optional json xml...
'App _ group_list'     
=> 'Home, admin', // Project Group
'Default _ group'      
=> 'Home', // default group

'Cookie _ expire'      
=>
3600,  //
Coodie Validity Period
'Cookie _ Domain'      
=>
'',    
// Valid cookie Domain Name
'Cookie _ Path'        
=>
'/',   
// Cookie Path
'Cookie _ prefix'      
=>
'',    
// Cookie prefix to avoid conflict

'Html _ cache_on'      
=> False, 
// Disable static cache by default
'Html _ cache_time'    
=>
60,    
// Static cache Validity Period
'Html _ read_type'     
=>
0,     
// Static cache read method 0 readfile 1 redirect
'Html _ file_suffix'   
=> '.Shtml ', // default static file suffix

'Error _ message'      
=> 'The page you browsed has an error temporarily! Please try again later ~ ', // Error display information, not in debug mode
'Error _ page'         
=> '', // Error targeting page

The defined model files are stored in the LIB/model directory of the project and are automatically loaded by the system.

Instantiate basic model class

$ Xx = new model ('xx'); or $ XX= M ('xx ');

Instantiate a user-defined model

$ User = D ('user ');

Instantiate an empty model $ model = new model ();

The model name seems to correspond to the database field, so there is a deviation. There is a specification...

Thinkphp
Naming of database table names and model classes follows certain standards. First, all the table names and fields in the database are in lowercase. The naming rule of the model class is to remove the table name with the table prefix, and the first letter is in uppercase. Then, the suffix of the model class is added.

You can set this attribute when the table prefix is consistent with the system prefix (db_prefix) but the table name and model name are inconsistent. For example, the table name is users.
And the model name is usermodel, you need to set it in the model class:

Differences between m and D methods

Both the M and D methods in thinkphp are used to instantiate a model class. The M method is used to efficiently instantiate a basic model class, while
D is used to instantiate a user-defined model class.

Class usermodel extends model {
   Protected
$ Tablename = 'users ';
}

Use m METHOD

If the following is the case, consider using the M method:

  1. When performing simple curd operations on a data table without complex business logic
  2. Only when some tables have complicated business logic, the M method and the instantiated commonmodel class are used in combination.

The m method can even be simply used to operate the data table corresponding to the parameter table name:

$User = M('User');
Use method D

If the following is the case, consider using the D method:

  1. You need to use some advanced features in the thinkphp model, such as the auto-verification feature (implemented in the CREATE () method) and associated model.
  2. The business logic is complex and involves a large number of tables
  3. Define the business logic in the custom model class (under the LIB/model directory), and want to implement these business logic in the operation

In addition, the method D does not support cross-project calls. You need to use the following:

$ User = D ('user', 'admin'); // instantiate the user model under the admin project $ user = D ('admin. user'); // the project group is enabled.

If the table prefix is inconsistent with that set by the system (the table name and model name may be the same), you must set the truetablename attribute of the model:

Class usermodel extends model {
   Protected
$ Truetablename = 'my _ user ';
}

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.