为了账号安全,请及时绑定邮箱和手机立即绑定

老师分我改了下

<?php
 class functionsController{
  function add(){
   if (empty($_POST)){
    if (isset($_GET['id'])){
     $functionsObj = M('functions');
     $data = $functionsObj->findOne_by_id($_GET['id']);
    }else{
     $data = array();
    }
    VIEW::assign(array('data'=>$data));
    VIEW::display('system/functions.html');
   }else{
    $functionsObj = M('functions');
    //$result = $functionsObj->add($_POST);
    //$this->swich_result($result);
    if(empty($_POST['title'])||empty($_POST['controller'])||empty($_POST['method'])){
     return 0;
    }else{
     if ($_POST['id']==""){
      $functionsObj->add($_POST);
      $this->swich_result(1);
     }else{
      $functionsObj->update($_POST);
      $this->swich_result(2);
     }
    }
   }
  }
  function show(){
   $functionObj = M('functions');
   $data = $functionObj->findAll();
   VIEW::assign(array('data'=>$data));
   VIEW::display('system/functionsList.html');
  }
  
  private function swich_result($result){
   if($result == 0){
    $this->showmessage('操作失败!','http://localhost/index.php?controller=functions&method=add&id='.$_POST['id']);
   }
   if($result == 1){
    $this->showmessage('添加成功!','http://localhost/index.php?controller=functions&method=show');
   }
   if($result == 2){
    $this->showmessage('修改成功!','http://localhost/index.php?controller=functions&method=show');
   }
  }
  
  private function showmessage($info, $url){
   echo "<script>alert('$info');window.location.href='$url'</script>";
   exit;
  }
 }


<?php
class functionsModel {
 
 public $_table = 'functions';
 
 function add($data){
  extract($data);
 
  $title = addcslashes($title);
  $controller = addslashes($controller);
  $method = addslashes($method);
  $parent_id = addslashes($parent_id);
  $data = array('title'=>$title,'controller'=>$controller,'method'=>$method,'parent_id'=>$parent_id);
  DB::insert($this->_table,$data);
 }
 
 function delete_by_id($id){
  $id = intval($id);
 }
 
 function update_by_id($data){
  extract($data);
  $data = array('title'=>$title,'controller'=>$controller,'method'=>$method,'parent_id'=>$parent_id);
  DB::update($this->_table,$data,'id='.$id);
 }
 
 function findOne_by_id($id){
  $id = intval($id);
  $sql = 'select * from funcitons where id ='.$id;
  return DB::findOne($sql);
 }
 function findAll(){
  $sql = 'select * from functions';
  return DB::findAll($sql);
 }
}
?>

正在回答

2 回答

改的不错

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

老师分我改了下

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信