thinkphp--Development Common

Source: Internet
Author: User

1. Custom Controller

Name: WenjianController.class.php

Name capitalize, controller name Controller.class.php

// cannot have spaces or blank lines namespace Home\controller;  // Namespace Module Name \controller Note Case  Use  classextends  controller{}

2. Instantiation Model three ways to:

    1. $goods = new namespace Goodsmodel ();
    2. $goods = D (' model sign ');

a) $goods = D ("goods");

b) The $goods is the object of the parent model, but the data table of the operation is still sw_goods

c) $obj = D (); Instantiate the model object with no specific operational data tables, consistent with the M () method effect

    1. $obj = M ();

A) instantiation of the parent class model

b) You can directly invoke the properties inside the parent model to get database related operations

c) Custom model is an empty shell, there is no need to instantiate a custom model

d) $obj = M (' Data sheet sign '); Instantiate the model object and actually manipulate the specific data table

$obj = D (sign);

$obj = D ();

$obj = M (sign);

$obj = M ();

The difference between the D () and M () methods:

The former is a simplified method for new operation in tp3.1.3;

The latter is used to instantiate the model parent class

Both are defined in the function library file thinkphp/common/functions.php

Note: If there is no corresponding model model file class, you can also instantiate the model object directly for operation

Both the D () and M () methods can be instantiated to manipulate a data table that does not have a specific model class file.

3. Consistent operation

$User->where (' Status=1 ')->order (' Create_time ')->limit ()->select (); Select Queries all data
$User->where (' Status=1 ')->order (' Create_time ')->limit ()->find ();//find Query Single data

4.foreach Traversal Array

<foreach name= "attr" item= "V" >//name for the array that needs to be traversed item is a temporary variable          <tr>            <td>{$v. name}</td>            <td>{$v.size}</td>            <td>{$v.user}</td>            <td>{$v.times}</td>            <td>{$v.shuoming}</td>            <td>{ $v.type}</td>          </tr></foreach>

5.ajax back

$this->ajaxreturn ($a, ' eval '); eval = return string

thinkphp--Development Common

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.