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.