2013-04-28 39 views
0

按照本教程:http://johnsquibb.com/tutorials/mvc-framework-in-1-hour-part-one簡單的MVC例如不工作的甲基苯丙胺本地主機

我有下面的代碼:

的index.php

<?php 

// Define document paths 
define('SERVER_ROOT', '/Applications/MAMP/Library'); 
define('SITE_ROOT', '/Applications/MAMP/htdocs') 

// Fetch the router 
require_once(SERVER_ROOT . '/controllers/' . 'router.php'); 

router.php

<?php 

//fetch the passed request 
$request = $_SERVER['QUERY_STRING']; 

//parse the page request and other GET variables 
$parsed = explode('&' , $request); 

//the page is the first element 
$page = array_shift($parsed); 

//the rest of teh array are get stateemnts, parse them out. 
$getVars = array(); 
foreach ($parsed as $argument) 
{ 
//split GET vars along '=' symbol to separate variable, values 
list($variable, $value) = split('=' , $argument); 
$getVars[$variable] = $value; 
} 

//this is a test, and we will be removing it later 

print "the page you requested is '$page'"; 
print '<br/>'; 
$vars = print_r($getVars, TRUE); 
print "The following GET Vards we passed to the page:<pre>".$vars."</pre>"; 

在此網址中輸入:

http://localhost/MVC_test/index.php?news&article=howtobuildaframework 

我得到這個錯誤:

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. 

我的甲基苯丙胺的主頁說我的文檔根目錄是:/Applications/MAMP/htdocs和我的服務器的根目錄是:/Applications/MAMP/Library

最後,路徑索引文件是:/Applications/MAMP/htdocs/MVC_test/index.php

我在做什麼錯?

回答

0

首先你在你的index.php有語法錯誤,你忘了把一個分號在第四行,所以更改代碼

// Define document paths 
define('SERVER_ROOT', '/Applications/MAMP/Library'); 
define('SITE_ROOT', '/Applications/MAMP/htdocs') 

這個

// Define document paths 
define('SERVER_ROOT', '/Applications/MAMP/Library'); 
define('SITE_ROOT', '/Applications/MAMP/htdocs'); 

其次loooks像你沒有用正確的路徑定義上述兩個變量,請確保SERVER_ROOT和SITE_ROOT是正確的,對我來說SITE_ROOT應該是類似於

define('SITE_ROOT', '/Applications/MAMP/htdocs/MVC_test'); 
+0

感謝您的回覆!我修正了愚蠢的語法錯誤,並嘗試了你建議沒有運氣的'SITE_ROOT'。你能告訴我一些通用的方法來整理這些路徑嗎? – dwstein 2013-04-28 10:17:49

相關問題