<?php
class MessagesAction extends CommonAction{
	// 首页
	public function index(){
		 $Messages	= M("Messages");
		//导入分页类
         import("@.ORG.Page");
        //取得满足条件的记录数
         $count = $Messages->count();
         $p = new Page($count, 5);
         //分页查询数据
         $list = $Messages->order('id desc')->limit($p->firstRow.','.$p->listRows)->select();
         //分页显示
         $page = $p->show();
         //模板赋值显示
         $this->assign('list',$list);
         $this->assign("count", $count);
         $this->assign("page", $page);
 
		 $this->display();
	}

        // 编辑数据 
    public function edit() { 
        if(!empty($_GET['id'])) { 
            $Messages    =    M("Messages"); 
            $vo    =    $Messages->getById($_GET['id']); 
            if($vo) { 
                $this->assign('vo',$vo); 
                $this->display(); 
            }else{ 
                exit('编辑项不存在！'); 
            } 
        }else{ 
            exit('编辑项不存在！'); 
        } 
    } 

     // 更新数据 
    public function update() { 
        $Messages    =    D("Messages"); 
        if($vo = $Messages->create()) { 
            $list=$Messages->save(); 
            if($list!==false){ 
                $this->success('数据更新成功！'); 
            }else{ 
                $this->error("没有更新任何数据!"); 
            } 
        }else{ 
            $this->error($Messages->getError()); 
        } 
    } 
    
	  // 删除数据 
    public function delete() { 
        if(!empty($_POST['id'])) { 
            $Messages    =    M("Messages"); 
            $result    =    $Messages->delete($_POST['id']); 
            if(false !== $result) { 
                $this->ajaxReturn($_POST['id'],'删除成功！',1); 
            }else{ 
                $this->error('删除出错！'); 
            } 
        }else{ 
            $this->error('删除项不存在！'); 
        } 
    } 
    
	
     public function _before_add() {
                $verify = build_verify(8);
                $_SESSION['attach_verify'] = $verify;
                $this->assign('verify',$verify);
        }
	

}
?>