Written in front of the words: should customer needs to add self-help to the background of the movie name and link function, added in the foreground can automatically read the display.
Development steps:
1, because is to add a movie and movie link to the background function, so the controller under the admin.
Create a new controller under path Application\lib\action\admin MvaddAction.class.php
The controller All code is as follows:
<?php//After inheriting publicaction, you must log in to the background before accessing this pageclassMvaddactionextendspublicaction { Public functionindex () {$result= M ("movie")Select (); //Var_dump ($result); exit; $this->assign ("Name",$result); $this-display (); } Public functionAdd () {$data["mvname"] =$_post["Name"]; $data["mvlink"] =$_post["Mvlink"]; $result= M ("movie")->add ($data); if($result){ $this->ajaxreturn ($result, "added success! ", 1); //echo "OK"; } } Public functiondel () {$id=$_post[' ID ']; $result= M ("movie")->where (Array("id" =$id)),Delete (); if($result){ $this->ajaxreturn ($result, "Delete success! ", 1); } } Public functionShow () {$id=$_get[' ID ']; $link= M ("movie")->where (Array("id" =$id)),find (); $this->assign ("link",$link[' Mvlink ']); $this-display (); }}
2. Add a template
Add a static page template under the Application\tpl\admin\mvadd directory index.html
A static page is a page that has been fully developed.
Front-end frame with bootstrap
<! DOCTYPE html>class= "Form-group" > <label for= "ExampleInputEmail1" > Movie name </label> <input type= "text"class= "Form-control" id= "mvname" placeholder= "Please enter movie name such as: Fine movie" > </div> <divclass= "Form-group" > <label for= "ExampleInputPassword1" > Movie link </label> <input type= "text"class= "Form-control" id= "Mvlink" placeholder= "movie Link: such as http://www.029gc.cn" > </div><button type= "button" id= " Addclass= "Btn btn-primary btn-lg btn-block" style= "Width:20%;align:center;" > Save </button></form><tableclass= "Table table-bordered" > <tr id= "tr" ><td> name </td><td> link </td><td> Action </td ></tr> <foreachName= "name" item= "VO" > <tr id= "{$vo. Id}tr "><td>{$vo. mvname}</td><td>{$vo. Mvlink}</td><td><a href= "javascript:void (0)" Onclick=dellink ({$vo. ID});> delete </a></td></tr> </foreach></table></body><script type=text/javascript>$("#add"). Click (function (){varName = $ ("#mvname").Val ();varlink = $ ("#mvlink").Val ();if(name== "" | | link== "") {alert ("Movie name or link cannot be empty");return;}Else{$.Ajax ({URL: ".. /index.php?g=admin&m=mvadd&a=add ",type: "POST",Data: {"name": Name, "Mvlink": Link},DataType: "JSON",Error:function() {alert (' Error loading XML document '); },Success:function(data) {Alert (Data.info); $("#tr"). After ("<tr id=" +data.data+ "tr><td>" +name+ "</td><td>" +link+ "</td><td> <a href= ' javascript:void (0) ' Onclick=dellink1 ("+data.data+");> Delete </a></td></tr> ") } });}}); functionDellink (ID) {$.Ajax ({URL: ".. /index.php?g=admin&m=mvadd&a=del ",type: "POST",Data: {"id": ID},DataType: "JSON",Error:function() {alert (' Error loading XML document '); },Success:function(data) {Alert (Data.info); $("#" +id+ "tr").Remove (); } });} </SCRIPT>
Technical points:
Dynamically add and delete data from a table.
thinkphp Ajax Additions and deletions