遵循本教程:http://johnsquibb.com/tutorials/mvc-framework-in-1-hour-part-one
我有以下代码:
的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.
我的MAMP主页说我的doc根目录是:/Applications/MAMP/htdocs
我的服务器根目录是:/Applications/MAMP/Library
最后,索引文件的路径是:/Applications/MAMP/htdocs/MVC_test/index.php
我做错了什么?
答案 0 :(得分: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');
其次就像你没有用正确的路径定义上面两个变量那样确保SERVER_ROOT和SITE_ROOT是正确的,对我来说,SITE_ROOT应该像
define('SITE_ROOT', '/Applications/MAMP/htdocs/MVC_test');