【发布时间】:2016-01-09 01:02:45
【问题描述】:
我是 PHP 新手。我正在使用来自 packagist.org 的联盟/路由在我的应用程序中进行路由,并且我的根目录中有一个公用文件夹,其中有一个 index.php 文件用于路由,如下所示。
require_once '../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$router = new League\Route\RouteCollection;
$router->addRoute('GET', '/acme', function (Request $request, Response $response) {
echo "here";
return "working";
});
$dispatcher = $router->getDispatcher();
$response = $dispatcher->dispatch('GET', '/acme');
$response->send();
.htaccess 文件如果在根文件夹,如下所示
RewriteEngine On
RewriteBase /HMT/public
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
问题是当我运行http://localhost/HMT/acme 时没有显示任何内容。我尝试在 public/index.php 文件的每一行之后添加一个 echo 语句,并注意到下面的行是行不通的。我也认为我的 .htaccess 可能是问题所在??
$dispatcher = $router->getDispatcher();
感谢您的帮助,谢谢。
【问题讨论】:
-
您应该会收到一条错误消息。尝试在索引文件的开头添加:
ini_set('display_errors',1);以进行调试。
标签: php .htaccess url-rewriting url-routing