iwebshop添加,删除,修改
<?php
class crud extends IController
{
public function add()
{
$this->redirect('add');
}
//添加
public function insed(){
$a = new IModel('crud');
$a->setData($_POST);
$b = $a->add();
if($b){
$this->redirect('show');
}else{
$this->error('add');
}
}
//展示
public function show(){
$a = new IQuery('crud');
$b = $a->find();
$this->setRenderData(['a'=>$b]);
$this->redirect('show');
}
//删除
public function del(){
$id = IReq::get('id');
$a = new IModel('crud');
$b = $a->del($id);
if($b){
$this->redirect('show');
}else{
echo "删除失败";
}
}
//修改
public function xg(){
$id = IReq::get('id');
$a = new IQuery('crud');
$a->where="id=$id";
$b= $a->find();
$this->setRenderData(['a'=>$b[0]]);
$this->redirect('updat',false);
}
public function sav(){
$id = IReq::get('id');
$name = IReq::get('name');
$pwd = IReq::get('pwd');
$phone = IReq::get('phone');
$email = IReq::get('email');
$word = IReq::get('word');
$age = IReq::get('age');
$obj = new IModel('crud');
$data = array('name'=>$name,'pwd'=>$pwd);
$obj->setData($data);
$res=$obj->update("id=$id");
if($res){
$this->redirect('show');
}else{
echo "修改失败";
}
}
}
?>