單個刪除實際上是TP中最容易的了,在列表頁遍歷的時候直接將ID傳給刪除這個A標籤便可:php
而後在 控制器接收:html
<?php namespace Admin\Controller; use Think\Controller; class AdminController extends Controller { public function lists(){ $mod = M('admin'); $totalRows = $mod->count(); //建立分頁對象時,分頁對象須要總記錄數和分頁條數 $page = new \Think\Page($totalRows,2); $page -> rollPage =3; //分頁列表上顯示多少條 $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); $page->setConfig('first','首頁'); $page->setConfig('prev','上一頁'); $page->setConfig('next','下一頁'); $page->setConfig('last','尾頁'); $pageHtml = $page -> show();//生成分頁的鏈接誒效果(分頁工具條的html代碼) $this -> assign('pageHtml',$pageHtml);//分配分頁欄到模版 //2.查詢出當前頁面的列表數據 $data = $mod ->order('id desc')->page(I('get.p',1),$page->listRows)->select(); $this -> assign('data',$data); $this -> display(); } public function add(){ $mod = D("admin"); if(IS_POST){ $data['username'] = I('username'); $data['password'] = I('pass'); $data['passer'] = I('passer'); if($data['password'] == $data['passer']){ $data['password'] = md5($data['password']); if($mod->create($data)){ if($mod->add($data)){ $this -> success('管理員添加成功'); }else{ $this->error('管理員添加失敗'); } }else{ $this->error($mod->getError()); } }else{ $this->error('確認密碼錯誤'); } return;//這裏的return主要是爲了防止跳轉 } $this -> display(); } public function edit(){ $this -> display(); } public function del(){ $id = I('id'); if(M('admin')->delete($id)){ $this->success('刪除成功'); return; }else{ $this->error('刪除失敗'); } $this -> display(); } }