thinkphp Lectures (eight)--display, modify, add, delete

Source: Internet
Author: User

First, display the data

  

Displays all data function Showinfo () {$model =d ("Info") $attr = $model->field ("Info.code as infocode,info.name as InfoName, Info.sex,nation.name as Nationname,info.birthday ")->join (" Nation on Info.nation=nation.code ")->select (); $ This->assign ("Shuju", $attr); $this->display ();}

  

Second, add data

  

Add Data function Tianjia () {if (empty ($_post)) {$model =d ("Nation"), $attr = $model->select (); $this->assign ("Shuju ", $attr); $this->display ();} else{$model =d ("Info"), $model->create (), $model->sex=$_post["Sex"]== "1" true:false; $z = $model->add (); if ( $z) {$this->success ("Add Success", "Tianjia");} else{$this->error ("Add failed! ");}}

  

Third, modify the data

  

  

Modify Data function Xiugai ($code) {$model =d ("Info"), $modeltion =d ("Nation"), if (Empty ($_post)) {$attr = $model->find ($ code); $attrtion = $modeltion->select (); $this->assign ("Shuju", $attrtion); $this->assign ("info", $attr); $ This->display ();} else{$model->create (); $model->sex=$_post["Sex"]==1?ture:false; $z = $model->save (); if ($z) {$this Success ("Modified successfully! ", U (" Showinfo "));} else{$this->error ("Modify failed! ");}}}

  

Iv. deletion of data

Delete action method function Shanchu ($code) {$model =d ("Info"), $z = $model->delete ($code), if ($z) {$this->success ("Delete succeeded", U ( "Showinfo"));} else{$this->error ("delete failed");}}

  

thinkphp Lectures (eight)--display, modify, add, delete

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.