The difference between database access crud;__self__ and __action__; automatic collection of forms: $n->create ();

Source: Internet
Author: User

I. TP Framework data access (PDO Foundation)

 Public functionTest () {$n= D ("Nation"); //Select (); Find (); Enquiry1.$attr=$n->select ();//check all, return an associative array, two-dimensional associative array2.$attr=$n->select ("n001,n002");//based on the parameter (primary key value)3.$attr=$n->find ("n002");//Check One piece of data, one-dimensional array//where//coherent operation4.$n->where ()->select ();//add condition, $n->where () returns an object      $n->where ("Name=> ' Han ' or name= ' hui '")Select (); 5.table//If you look for data other than the Nation table, use table      $attr=$n->table ("info")Select (); 6.field//Specify a field query (check a few columns)      $attr=$n->field ("code")Select (); 7.order//Sort      $attr=$n->order ("Code desc")Select (); 8.limit//page Out      $a=$n->limit (3,5)->select ();//Skip 3 data to fetch 5 data      $a=$n->limit (3)->select ();//Fetch 3 Data9.page//page Out      $a=$n->page (3,5)->select ();//the 3rd page shows 5 data, according to the number of pages from the dynamic paging10.group//Grouping      $a=$nation->field ("Brand,avg (Price)")->group ("Brand")Select (); 11.having//Finish group plus conditions      $a=$nation->field ("Brand,avg (Price)")->group ("Brand")->having ("avg. >40")Select (); 12.distinct//Go heavy      $a=$nation->field ("Brand")->distinct (true),Select (); 13.getField//gets the data for a field, only queries the column name, does not write where condition, default to the least-indexed field      $a=$nation->where ("code= ' n001 '")->getfield ("name"); 14.sum,Count,Max,min       $a=$nation->table ("Car")sum (price); 15.Join.. On//the column that asks for the query is given an alias display, and the alias is customized to      $a=$nation->field ("Info.code as ' code ', info.name as ' name ', nation.name as ' People '")Join("Info on Info.nation=nation.code")Select (); 16.cache//Data Caching17.query//Native SQL statement query      $sql= "SELECT * From Nation"; $a=$nation->query ($sql); 18.execute//Native SQL statement other actions modified     $sql= "Update Nation set name= ' Manchu ' where code= ' n001 '"; $a=$nation->execute ($sql); Var_dump($a);}
View Code

Second, automatic collection of forms:

application/lianxi/controller/maincontroller.class.php

<?phpnamespace Lianxi\controller; UseThink\controller;classMaincontrollerextendscontroller{ Public functionBiaodan () {//implement two logical//1. Display Add page 2. Adding data to a database        if(Empty($_post))        {            $this-Show (); }        Else        {            $n= D ("Nation"); $n->create ();//automatically collect the form, provided that the post data is required, if the post is empty, go to the name of input in the if;html page must correspond to the column name of the database table, case sensitive            $z=$n-Add (); if($z)            {                //Jump Method One//$this->success ("Add Success", "Biaodan", 5);//5 is jump time, Interval 5 sec//Jump method two                $this->redirect (' Biaodan ',Array(), 5, "page jump ...");//Array (' ID ' =>2), jump page can pass parameters, associated            }            Else            {                $this->error ("Add failed!");//one parameter, error failure returns to the previous page by default            }        }    }        //using the Address bar to pass parameters, such as: Main/canshu/id/5, method to accept the use of     Public functionCanshu ($id)    {        //method One//echo $_get["id"]; Method Two: Canshu ($id)        Echo $id;//if the $id is assigned a value of Canshu ($id =0), the address bar does not give the parameter will not error    }}
View Code

Application/lianxi/view/main/biaodan.html

View Code

1. How to remove the error message after the page fails:

2. The question where the ACTION in the form <form> is pointing: Point to __self__ or __action__

First Var_dump (Get_defined_constants (True)), display system constants, find __self__ and __action__;

__self and __action__ differences: __self__ access is itself, is the browser access to the address, such as: localhost/tp/index.php/home/main/biaodan/code/ (Code and 10 are arbitrary arguments), __action__ can only access to Biaodan (method) here

The difference between database access crud;__self__ and __action__; automatic collection of forms: $n->create ();

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.