【问题标题】:simple MVC example not working on MAMP localhost简单的 MVC 示例不适用于 MAMP localhost
【发布时间】:2013-04-28 10:01:08
【问题描述】:

跟随本教程: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');

路由器.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

我做错了什么?

【问题讨论】:

    标签: php localhost url-routing mamp


    【解决方案1】:

    首先你的 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');
    

    【讨论】:

    • 感谢您的回复!我修复了愚蠢的语法错误并尝试了您建议的SITE_ROOT,但没有成功。你能告诉我一些通用的方法来整理这些路径吗?
    猜你喜欢
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多