老師分我改了下
<?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);
?}
}
?>
2015-03-02
改的不錯(cuò)
2022-03-23
額里面的display拼錯(cuò)了。。創(chuàng)建的自定義函數(shù)和系統(tǒng)的內(nèi)置函數(shù)<strong>重名</strong>了!