thinkphp study 03

Source: Internet
Author: User

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

Public Function Index () {$name = "Pandanus"; $this->assign (' name ', $name);  Assign the $name to the variable name so that the template gets  $this->display ();    }

Template get

Create a module folder under the corresponding TPL (note case), create HTML for the corresponding method name

1 2 3 <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">4 <title>insert title here</title>5 6 < body>7    Hello world,{$name}8 </body>9 

To avoid conflicts, it is recommended that you modify the delimiter for the output of the configuration item below

' Tmpl_l_delim ' = ' <{',//Modify left delimiter ' tmpl_r_delim ' = '}> ',//Modify right delimiter

<body>   Hello world,<{$name}></body>

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

Ii. model use of thinkphp 3 (emphasis)

You need to manipulate the database in a method by using the new Model (table name)

Public Function Index () {  $m =new Model (' user ');  In config.php configuration, call the user table $arr = $m->select (); Query Var_dump ($arr);     }

Setting up Database information in config.php

' 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 following configuration equivalent

' Db_dsn ' + ' Mysql://root: @localhost: 3306/thinkphp ',  //Configure database information using DSN mode, simplify database configuration ' db_prefix ' = ' tp_ ',// Set Table prefixes

If both methods are present, the DSN is preferred

Thinkphp Learning

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.