Learn Thinkphp3.1 in two hours (mostly from thinkphp3.1 Quick Start) and thinkphp3.1 Quick Start

Source: Internet
Author: User

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

 

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.