0

按照本教程:http: //johnsquibb.com/tutorials/mvc-framework-in-1-hour-part-one

我有以下代码:

索引.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');

路由器.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 主页显示我的文档根目录是:/Applications/MAMP/htdocs而我的服务器根目录是:/Applications/MAMP/Library

最后,索引文件的路径是:/Applications/MAMP/htdocs/MVC_test/index.php

我究竟做错了什么?

4

1 回答 1

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');
于 2013-04-28T10:11:33.900 回答