thinkphp study 04

Source: Internet
Author: User
Tags dsn

I. Output of thinkphp 3 (emphasis)

A, through the Echo and other PHP native output mode in the page output

B. You can use the Assign method to output the variable you want to assign by using the Display method

C, modify the left and right delimiter Hugh to modify configuration items in the configuration file ' Tmpl_l_delim ' + ' <{',//Modify the left delimiter ' tmpl_r_delim ' + '}> ',//modify the correct delimiter

Second, thinkphp 3 model use (emphasis) needs to be in the form of New Model (table name) to manipulate the database

$m =new Model (' User ');

$arr = $m->select ();

' Db_type ' = ' mysql ',//Set Database type

' db_host ' = ' localhost ',//Set host

' Db_name ' = ' thinkphp ',//Set database name

' Db_user ' + ' root ',//set user name

' Db_pwd ' + ',//Set Password

' Db_port ' = ' 3306 ',//Set port number

' Db_prefix ' = ' tp_ ',//Set table prefix

You can also use the DSN method to configure ' db_dsn ' = ' mysql://root: @localhost: 3306/thinkphp ',//Configure database information using DSN mode

If both methods are present, the DSN takes precedence

There is also a simple and practical way to model M () equivalent to the new model ();  $m =m (' User '); $arr = $m->select ();

Using instances of the model can manipulate the data, the operation is generally to the database for the deletion of the search curd

Add-C Create $m->add ()

Delete-D delete $m->delete ()

Change-u Update $m->save ()

Check-R Read $m->select ()

Iii. Supplementary (understanding)

A, the template can traverse the array

Passing data to a template on the action layer

Public Function Index () {  $m =new Model (' user ');  In config.php configuration $arr = $m->select ();//Var_dump ($arr); $this->assign (' data ', $arr); $this->display ();    }

Receiving data traversal at the TPL template layer

<volist name= ' data ' id= ' voc22 ' >     <{$voc 22.id}>---<{$voc 22.username}>-----<{$VOC 22.sex} ><br/>   </volist>//Outer volist label cannot be modified

b, we can open the debug function in the Page_trace "

1. Turn on the Debug function//Turn on Debug mode define (' App_debug ', true);

2. We need to set config file, open page trace ' show_page_trace ' =>true,//open page trace

thinkphp study 04

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.