Learn Thinkphp3.1 in two hours (mostly from thinkphp3.1 Quick Start) and thinkphp3.1 Quick Start
Debugging mode
define('APP_DEBUG',TRUE);
Define automatic verification
Protected $ _ validate = array ('title', 'require ', 'title '),);
Search for read data
$ Form = M ('form'); // read data $ data = $ Form-> find ($ id); // here, the M method is used instead of the D method, because the find method is a method in the Model of the basic Model class, there is no need to waste the overhead to instantiate the FormModel class.
Obtains the value of a field.
$title = $Form->where('id=3')->getField('title');
Query Method
1: $ User-> where ('Type = 1 AND status = 1')-> select (); 2: // use an array $ User = M ("User "); // instantiate the User object $ condition ['name'] = 'thinkphp'; $ condition ['status'] = 1; // input the query condition into the query method $ User-> where ($ condition)-> select (); 3: // use the object $ User = M ("User "); // instantiate the User object // define the query condition $ condition = new stdClass (); $ condition-> name = 'thinkphp'; $ condition-> status = 1; $ User-> where ($ condition)-> select (); 4: // different query conditions for different fields $ User = M ("User "); // instantiate the User object $ map ['status & title'] = array ('1', 'thinkphp', '_ multi' => true ); // input the query condition into the query method $ User-> where ($ map)-> select ();
Get variable
$ Id = $ this-> _ get ('id'); // get the get variable $ name = $ this-> _ post ('name '); // get the post variable $ value = $ this-> _ session ('var'); // get the session variable $ name = $ this-> _ cookie ('name '); // get the cookie variable $ file = $ this-> _ server ('php _ SELF '); // get the server variable
Define routing rules:
'Url _ route_rules' => array (// define the routing rule 'new/: id \ d' => 'news/read', 'new /: name '=> 'news/read', 'new/: year \ d/: month \ d' => 'news/archive ',),
View Code
The following address can be used for access:
http://serverName/index.php/new/8
Jump page:
Redirect (U ("Form/regist"), 1, "user name does not exist, will jump to registration"); $ this-> redirect (U ("Form/regist"), 1, "The user name does not exist and is about to jump to registration"); // This sentence will only print the content and will not jump