亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

老師分我改了下

<?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下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號