哪里錯(cuò)了?。?/h1>
這是我的結(jié)構(gòu)文件:/var/www/html/test/MVC/
├── test
│?? ├── MVC
│?? │?? ├── Controller
│?? │?? │?? └── testController.class.php
│?? │?? ├── function.php
│?? │?? ├── index.php
│?? │?? ├── Model
│?? │?? │?? └── testModel.class.php
│?? │?? ├── test.php
│?? │?? └── View
│?? │?????? └── testView.class.php
│?? └── others
/test/MVC/Controller/testController.class.php
<?php
class?testController{
????function?show(){
????????//$testModel?=?new?testModel();
????????$testModel?=?Model('test');
????????$data=$testModel->get();
????????//$testView?=?new?testView();
????????$testView?=?View('test');
????????$testView->display($data);
????}
}
?>
/test/MVC/Model/testModel.class.php
<?php
????class?testModel{
????????function?get(){
????????????echo?"Hello?World!";
????????}
????}
?>
/test/MVC/View/testView.class.php
<?php
class?testView{
????function?display($data){
????????echo?$data;
????}
}
?>
function.php
<?php
????function?Controller($name,$method){
????????require_once('/test/MVC/Controller/'.$name.'Controller.class.php');
????????//$testController?=?new?testController();
????????//$testController->show();
????????eval('$obj?=?new'.$name.'Controller();?$obj->'.$method.'();');
????}
????Controller('test','show');
????function?Model($name){
????????require_once('/test/MVC/Model/'.$name.'Model.class.php');
????????//$testModel?=?new?testModel();
????????eval('$obj?=?new?'.$name.'Model();');
????????return?$obj;
????}
????function?View($name){
????????require_once('/test/MVC/View/'.$name.'View.class.php');
????????//$testView?=?new?testView();
????????eval('$obj?=?new?'.$name.'View();');
????????return?$obj;
????}
????function?daddslashes($str){
????????return?(!get_magic_quotes_gpc())?addslashes($str):$str;
????}
?>
index.php
<?php
????//url形式?index.php?controller=控制器名&method=方法名
????require_once('function.php');
????$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';
????Controller($controller,$method);
?>
報(bào)的錯(cuò)誤信息:
http://127.0.0.1/test/MVC/
Warning:?require_once(/test/MVC/Controller/testController.class.php):?
failed?to?open?stream:?No?such?file?or?directory?in?
/var/www/html/test/MVC/function.php?on?line?3
Fatal?error:?
require_once():?Failed?opening?required?
'/test/MVC/Controller/testController.class.php'?
(include_path='.:/usr/local/php/lib/php')?in?
/var/www/html/test/MVC/function.php?on?line?3
哪里錯(cuò)了啊……看不出來(lái)……
解決方案:
function.php
<?php
????function?Controller($name,$method){
????????require_once('Controller/'.$name.'Controller.class.php');
????????//$testController?=?new?testController();
????????//$testController->show();
????????eval('$obj?=?new'.$name.'Controller();?$obj->'.$method.'();');
????}
????Controller('test','show');
????function?Model($name){
????????require_once('Model/'.$name.'Model.class.php');
????????//$testModel?=?new?testModel();
????????eval('$obj?=?new?'.$name.'Model();');
????????return?$obj;
????}
????function?View($name){
????????require_once('View/'.$name.'View.class.php');
????????//$testView?=?new?testView();
????????eval('$obj?=?new?'.$name.'View();');
????????return?$obj;
????}
????function?daddslashes($str){
????????return?(!get_magic_quotes_gpc())?addslashes($str):$str;
????}
?>
這是我的結(jié)構(gòu)文件:/var/www/html/test/MVC/
├── test
│?? ├── MVC
│?? │?? ├── Controller
│?? │?? │?? └── testController.class.php
│?? │?? ├── function.php
│?? │?? ├── index.php
│?? │?? ├── Model
│?? │?? │?? └── testModel.class.php
│?? │?? ├── test.php
│?? │?? └── View
│?? │?????? └── testView.class.php
│?? └── others
/test/MVC/Controller/testController.class.php
<?php class?testController{ ????function?show(){ ????????//$testModel?=?new?testModel(); ????????$testModel?=?Model('test'); ????????$data=$testModel->get(); ????????//$testView?=?new?testView(); ????????$testView?=?View('test'); ????????$testView->display($data); ????} } ?>
/test/MVC/Model/testModel.class.php
<?php ????class?testModel{ ????????function?get(){ ????????????echo?"Hello?World!"; ????????} ????} ?>
/test/MVC/View/testView.class.php
<?php class?testView{ ????function?display($data){ ????????echo?$data; ????} } ?>
function.php
<?php ????function?Controller($name,$method){ ????????require_once('/test/MVC/Controller/'.$name.'Controller.class.php'); ????????//$testController?=?new?testController(); ????????//$testController->show(); ????????eval('$obj?=?new'.$name.'Controller();?$obj->'.$method.'();'); ????} ????Controller('test','show'); ????function?Model($name){ ????????require_once('/test/MVC/Model/'.$name.'Model.class.php'); ????????//$testModel?=?new?testModel(); ????????eval('$obj?=?new?'.$name.'Model();'); ????????return?$obj; ????} ????function?View($name){ ????????require_once('/test/MVC/View/'.$name.'View.class.php'); ????????//$testView?=?new?testView(); ????????eval('$obj?=?new?'.$name.'View();'); ????????return?$obj; ????} ????function?daddslashes($str){ ????????return?(!get_magic_quotes_gpc())?addslashes($str):$str; ????} ?>
index.php
<?php ????//url形式?index.php?controller=控制器名&method=方法名 ????require_once('function.php'); ????$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'; ????Controller($controller,$method); ?>
報(bào)的錯(cuò)誤信息:
http://127.0.0.1/test/MVC/
Warning:?require_once(/test/MVC/Controller/testController.class.php):? failed?to?open?stream:?No?such?file?or?directory?in? /var/www/html/test/MVC/function.php?on?line?3 Fatal?error:? require_once():?Failed?opening?required? '/test/MVC/Controller/testController.class.php'? (include_path='.:/usr/local/php/lib/php')?in? /var/www/html/test/MVC/function.php?on?line?3
哪里錯(cuò)了啊……看不出來(lái)……
解決方案:
function.php
<?php ????function?Controller($name,$method){ ????????require_once('Controller/'.$name.'Controller.class.php'); ????????//$testController?=?new?testController(); ????????//$testController->show(); ????????eval('$obj?=?new'.$name.'Controller();?$obj->'.$method.'();'); ????} ????Controller('test','show'); ????function?Model($name){ ????????require_once('Model/'.$name.'Model.class.php'); ????????//$testModel?=?new?testModel(); ????????eval('$obj?=?new?'.$name.'Model();'); ????????return?$obj; ????} ????function?View($name){ ????????require_once('View/'.$name.'View.class.php'); ????????//$testView?=?new?testView(); ????????eval('$obj?=?new?'.$name.'View();'); ????????return?$obj; ????} ????function?daddslashes($str){ ????????return?(!get_magic_quotes_gpc())?addslashes($str):$str; ????} ?>
2015-10-01
路徑問(wèn)題。在linux里面 require 使用絕對(duì)路徑 / 開(kāi)頭的話,會(huì)從linux的根目錄開(kāi)始找,而不是你網(wǎng)站的根目錄。
2015-10-08
require_once('Controller/'.$name.'Controller.class.php');
換成這個(gè)就打印出Hello World!了!
2015-09-30
? require_once('/test/MVC/Controller/'.$name.'Controller.class.php');改成
? require_once('/Controller/'.$name.'Controller.class.php');試試
2015-09-30
? ? ??require_once('/test/MVC/Controller/'.$name.'Controller.class.php');這個(gè)的話,確實(shí)寫(xiě)得沒(méi)問(wèn)題嗎?
2015-09-30
你還是檢查一下目錄權(quán)限吧。