更新功能
This commit is contained in:
@@ -33,4 +33,17 @@ class Admin extends BaseController {
|
||||
$this->data['config'] = $config;
|
||||
}
|
||||
|
||||
protected function success($msg, $url){
|
||||
$this->data['code'] = 0;
|
||||
$this->data['msg'] = $msg;
|
||||
$this->data['url'] = $url->__toString();
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
protected function error($msg, $url){
|
||||
$this->data['code'] = 1;
|
||||
$this->data['msg'] = $msg;
|
||||
$this->data['url'] = $url->__toString();
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,18 +35,19 @@ class Client extends Admin{
|
||||
public function add(ClientModel $client){
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->param();
|
||||
$result = $client->validate(true)->save($data);
|
||||
$result = $client->save($data);
|
||||
if (false !== $result) {
|
||||
return $this->success('成功添加', url('client/index'));
|
||||
return $this->success('成功添加', url('/admin/client/index'));
|
||||
}else{
|
||||
return $this->error($this->model->getError());
|
||||
}
|
||||
}else{
|
||||
$info['appid'] = rand_string(10, 1); //八位数字appid
|
||||
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
|
||||
$data = array(
|
||||
$this->data['data'] = array(
|
||||
'info' => $info
|
||||
);
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
@@ -57,15 +58,20 @@ class Client extends Admin{
|
||||
public function edit(ClientModel $client){
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->param();
|
||||
$result = $client->validate(true)->save($data, array('id'=>$request->param('id')));
|
||||
if (!isset($data['id']) || !$data['id']) {
|
||||
return $this->error('非法操作!');
|
||||
}
|
||||
|
||||
$result = $client->where(array('id'=>$data['id']))->save($data);
|
||||
if (false !== $result) {
|
||||
return $this->success('修改添加', url('client/index'));
|
||||
return $this->success('修改成功', url('/admin/client/index'));
|
||||
}else{
|
||||
return $this->error($this->model->getError());
|
||||
}
|
||||
}else{
|
||||
$info = $client->where('id', $this->request->param('id'))->find();
|
||||
$data = array(
|
||||
$this->data['template'] = "add";
|
||||
$this->data['data'] = array(
|
||||
'info' => $info
|
||||
);
|
||||
return $this->data;
|
||||
|
||||
Reference in New Issue
Block a user