如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
增
public function add(){
$this->assign('title','添加用户');
$this->display('User/add');
}
public function insert(){
if(IS_POST){
M('user')->create();
if(M('user')->add()>0){
$this->success('添加成功',U('Home/Index/index'));
}else{
$this->error('添加失败');
}
}else{
E('非法访问');
}
}
删
<a href="{{:U('Index/del',array('id'=>$val['id']))}}">删除</a>
public function del(){
if(IS_GET){
$id = I('get.id',0,'int');
if(M('user')->delete($id)>0){
$this->success('删除成功',U('Home/Index/index'));
}else{
$this->error('删除失败');
}
}else{
E('非法访问');
}
}
改
<a href="{{:U('Index/edit',array('id'=>$val['id']))}}">编辑</a>
<form action="{{:U('index/editdo')}}" method="post">
public function edit(){
if(IS_GET){
$id = I('get.id',0,'int');
$row = M('user')->find($id);
$this->assign('title','修改信息');
$this->assign('row',$row);
$this->display('User/edit');
}
}
public function editdo(){
if(IS_POST){
$id = I('post.id',0,'int');
$user =M('user');
$user->name = I("post.name");
$user->pwd = I("post.pwd");
$user->tel = I("post.tel");
$user->email = I("post.email");
$res = $user->where("id=$id")->save();
if($res>0){
$this->success('修改成功',U('Home/Index/index'));
}else{
$this->success('修改失败',U('Home/Index/index'));
}
}else{
E('非法访问');
}
}
查
//全查
public function index(){
$list = M('user')->select();
$this->assign('title','用户中心');
$this->assign('list',$list);
$this->display('User/index');
}
//单查
$row = M('user')->find($id);
//带条件全查
M('user')->order('id desc')->limit(5)->select()