Sixth day thinkphp Quick Stitching website (vi)

Source: Internet
Author: User
February 22, sunny day-haze. "Osmanthus floral stuffing wrapped walnut, glutinous rice such as pearl water Amoy." See said Horse home drop powder good, test lamp wind in sell Yuanxiao. "

Ten, backstage writing-continued-3

1. writing The index method of the Action module , as well as the methods of adding or deleting.

 Assign (' title ', ' Add News '), $this->assign (' username ', session (' username ')), if ($id = (int) $_get[' id ') {$news =m (' News '), $news _item= $news->where ("id= $id")->find (); $this->assign (' News_item ', $news _item); $this Assign (' Btn_ok_text ', ' complete modification '), $this->assign (' btn_ok_act ', ' Update ');} else{$this->assign (' btn_ok_act ', ' Add '), $this->assign (' Btn_ok_text ', ' Add article ');} $this->display ();} /** * @ Function Add * @ Function News add complete, write to Database */function Add () {header ("content-type:text/html; Charset=utf-8 "), $News = D (' News '), if ($News->create ()) {$News->message=$_post[' editorvalue ']; $News- Author=session (' username ');//write the article to the database if ($News->add ()) {$this->success (' news added successfully, return to Superior page ', U (' Index/index '));} else{$this->error (' News add failed, return to parent page ');}} else{$this->error ($News->geterror ());}} /** * @ Function Quit * @ function Logout account, jump to login page. and clear session */function quit () {session (null);//Clear All Session information Redirect (U ('/login/index '), 0, ' re-login ');} /** * @ Function Delete * @ function remove Article */function Delete () {$news =m (' News '), if ($news->delete ($_get[' id ')) {$this->success (' article deletion succeeded ');} else{$this->error ($news->getlastsql ());}} /** * @ Function Edit * @ feature editing article */function edit () {header ("content-type:text/html; Charset=utf-8 "), if ($_get[' id ']) {redirect (U ('/news/index/id/'. $_get[' id '), 0, ' edit article ');}} /** * @ Function Update * @ Feature updates the modified article to database */public function update () {header ("content-type:text/html; Charset=utf-8 "); $news =m (' News '); $data = Array (' Subject ' =>$_post[' subject '], ' message ' =>$_post[' Editorvalue ' ], ' Createtime ' =>time (), ' LastModifyTime ' =>time ()); $id =$_post[' id ']; $news->where (' id= ' $id) SetField ($data); Save modified data according to condition $this->success (' News modified successfully, return to Superior page ', U (' Index/index '));}}


The above on the sixth day thinkphp hands-on Quick splicing website (vi), including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.