//添加数据的方法
function insert() {
$name=$this->getActionName();//获取当前的控制名
$model = D ($name);//
if (false === $model->create ()) {
$this->error ( $model->getError () );
}
//保存当前数据对象
$list=$model->add ();
if ($list!==false) { //保存成功
$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );//跳转页面
$this->success ('新增成功!');
} else {
//失败提示
$this->error ('新增失败!');
}
}
//展示添加界面
public function add() {
$this->display ();
}
//修改数据的方法
function update() {
$name=$this->getActionName();
$model = D ( $name );
if (false === $model->create ()) {
$this->error ( $model->getError () );
}
// 更新数据
$list=$model->save ();
if (false !== $list) {
//成功提示
$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
$this->success ('编辑成功!');
} else {
//错误提示
$this->error ('编辑失败!');
}
}
//显示编辑界面
function read() {
$this->edit ();
}
function edit() {
$name=$this->getActionName();
$model = M ( $name );
$map[$model->getPk ()] = $_REQUEST [$model->getPk ()];
$vo = $model->where($map)->find();
$this->assign ( 'vo', $vo );
$this->display ();
}
//删除方法
public function delete() {
//删除指定记录
$name=$this->getActionName();
$model = M ($name);
if (! empty ( $model )) {
$pk = $model->getPk ();//获取当前的模块的主键
$id = $_REQUEST [$pk];
if (isset ( $id )) {
$condition = array ($pk => array ('in', explode ( ',', $id ) ) );
$list=$model->where ( $condition )->setField ( 'status', - 1 );
if ($list!==false) {
$this->success ('删除成功!' );
} else {
$this->error ('删除失败!');
}
} else {
$this->error ( '非法操作' );
}
}
}
public function foreverdelete() {
//删除指定记录
$name=$this->getActionName();
$model = D ($name);
if (! empty ( $model )) {
$pk = $model->getPk ();
$id = $_REQUEST [$pk];
if (isset ( $id )) {
$condition = array ($pk => array ('in', explode ( ',', $id ) ) );
if (false !== $model->where ( $condition )->delete ()) {
//echo $model->getlastsql();
$this->success ('删除成功!');
} else {
$this->error ('删除失败!');
}
} else {
$this->error ( '非法操作' );
}
}
$this->forward ();
}
public function clear() {
//删除指定记录
$name=$this->getActionName();
$model = D ($name);
if (! empty ( $model )) {
if (false !== $model->where ( 'status=-1' )->delete ()) { // status=1 to status=-1
$this->assign ( "jumpUrl", $this->getReturnUrl () );
$this->success ( L ( '_DELETE_SUCCESS_' ) );
} else {
$this->error ( L ( '_DELETE_FAIL_' ) );
}
}
$this->forward ();
}