码迷,mamicode.com
首页 > 其他好文 > 详细

tp增删列表

时间:2015-07-15 19:09:40      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:

namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $this->display();
    }

     public function del($id){
         $result=false;
         $User=M("user");
         $result=$User->Where(‘id=‘.$id)->delete();
         if($result==false){
             echo json_encode(array(‘msg‘=>‘删除出错!‘));
         }else{
             echo json_encode(array(‘success‘=>true));
         }
     }
     public function save($id){
         $result=false;
         $User = M("User");
         $data[‘firstname‘] = $_REQUEST[‘firstname‘];
         $data[‘lastname‘] = $_REQUEST[‘lastname‘];
         $data[‘phone‘] = $_REQUEST[‘phone‘];
         $data[‘email‘] = $_REQUEST[‘email‘];
         $result=$User->where(‘id=‘.$_REQUEST[‘id‘])->save($data);
         if($result==true){
             echo json_encode(array(‘success‘=>true));
         }else{
             echo json_encode(array(‘msg‘=>‘更新出错!‘));
         }
     }
     
     public function add(){
         $result=false;
         $User=M("User");
         $data[‘firstname‘] = $_REQUEST[‘firstname‘];
         $data[‘lastname‘] = $_REQUEST[‘lastname‘];
         $data[‘phone‘] = $_REQUEST[‘phone‘];
         $data[‘email‘] = $_REQUEST[‘email‘];
         $result=$User->add($data);
         if($result==true){
             echo json_encode(array(‘success‘=>true));
         }else{
             echo json_encode(array(‘msg‘=>‘添加出错!‘));
         }
     }
     
     public function read(){
         $pagenum=isset($_POST[‘page‘]) ? intval($_POST[‘page‘]) : 1;
         $rowsnum=isset($_POST[‘rows‘]) ? intval($_POST[‘rows‘]) : 10;
         $User=M("User");
         $total = $User->count();    //计算总数 
         $userlist=array();
         $userlist=$User->limit(($pagenum-1)*$rowsnum.‘,‘.$rowsnum)->order(‘id asc‘)->select();
         $json=‘{"total":‘.$total.‘,"rows":‘.json_encode($userlist).‘}‘;//重要,easyui的标准数据格式,数据总数和数据内容在同一个json中
         echo $json;
     }
}

 

tp增删列表

标签:

原文地址:http://www.cnblogs.com/xsun8/p/4648944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!