第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Fatal error: Call to a member function display() on null 怎么解決??代碼都貼出來(lái)了

http://img1.sycdn.imooc.com//5aab40c6000105d112680213.jpg

index.php代碼

<?php

//url形式 index.php?controller=控制器&method=方法名

require_once('function.php'); //帶引號(hào)才行

$controllerAllow=array('test','index');

$methodAllow=array('test','index','show');

$controller=in_array($_GET['controller'],$controllerAllow)?daddslashes($_GET['controller']):'index';

$method=in_array($_GET['method'],$methodAllow)?daddslashes($_GET['method']):'index';

C($controller,$method);

?>

function.php代碼

<?php

function C($name,$method){ //C控制器縮寫(xiě)大 ,方法里面可以傳參數(shù),所以方法可以在傳參

require_once('/libs/Controller/'.$name.'Controller.class.php'); ?//引入控制器文件

eval('$obj=new '.$name.'Controller();$obj->'.$method.'();'); //eval()函數(shù)調(diào)用簡(jiǎn)單但是不安全

}

C('test','show');

function M($name){ ?//M模型縮寫(xiě)大 ,方法里面不可以傳參數(shù)

require_once('/libs/Model/'.$name.'Model.class.php');

/* $testModel=new testModel();//控制器 -> 按指令選取一個(gè)合適的模型

$data=$testModel->get(); //模型 ? -> 按控制器指令取相應(yīng)數(shù)據(jù) */

eval('$obj=new '.$name.'Model();');

return $obj;

}


function V($name){

require_once('/libs/View/'.$name.'View.class.php');

eval('$obj=new '.$name.'View();');

}


function daddslashes($str){ ? //daddslashes()用來(lái)轉(zhuǎn)義非法字符 函數(shù)返回在預(yù)定義字符之前添加反斜杠的字符串。

return(!get_magic_quotes_gpc())?addslashes($str):$str;

}


?>

testController.class.php代碼

<?php

class testController{

function show(){//控制器的作用是調(diào)用模型,并調(diào)用視圖。將模型產(chǎn)生的數(shù)據(jù)傳遞給視圖,并讓相關(guān)視圖去顯示

$testModel=M('test');?

$data=$testModel->get(); ? ?

$testView=V('test'); ??

$testView->display($data); ?

}

}

?>


正在回答

3 回答

謝謝?云彩無(wú)色3804005?貼出代碼

0 回復(fù) 有任何疑惑可以回復(fù)我~

首先你要確定,沒(méi)加index.php之前,訪問(wèn)你的代碼function.php你的代碼沒(méi)有錯(cuò)誤,如果有,說(shuō)明是你的幾個(gè)函數(shù)哪里寫(xiě)錯(cuò)了,如果沒(méi)有,說(shuō)明是index.php寫(xiě)錯(cuò)了。然后你在看你傳入的controller和method,先打印出你傳入的controller和method,再看看有沒(méi)有問(wèn)題。

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

云彩無(wú)色3804005 提問(wèn)者

我找到問(wèn)題了,是視圖函數(shù)少了個(gè)返回值return $obj; 謝謝
2018-03-21 回復(fù) 有任何疑惑可以回復(fù)我~

這個(gè)事說(shuō)你的對(duì)象沒(méi)有display方法,我看你是view調(diào)用的display方法,看看testView.class.php中你對(duì)testView這個(gè)class定義display這個(gè)方法了嗎

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

云彩無(wú)色3804005 提問(wèn)者

<?php class testView{ function display($data){ echo $data; } } ?>
2018-03-20 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

Fatal error: Call to a member function display() on null 怎么解決??代碼都貼出來(lái)了

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)