找不到苗条框架页面
slim framework Page not Found
不明白,这不是我第一次在 slim 下启动项目,但我有一个无法解释的错误。
我的文件夹:
c:\wamp\www\slim
我创建了 "public" 文件夹
c:\wamp\www\slim\public
如文档所说,我创建了 2 个 .htaccess:
在根目录中:
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/ [L]
在 public 文件夹中:
# Redirect to front controller
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
这是我的 index.php 在 public 文件夹中:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App;
var_dump($_SERVER);
$app->get('/', function (Request $request, Response $response) {
$response->getBody()->write("Hello");
return $response;
});
$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
如果我尝试转到:http://localhost/slim/ :: 找不到页面
如果我尝试转到:http://localhost/slim/hello/Alex :: 找不到页面
只有我这样设置我的路线才有效:
$app->get('/slim/hello/{name}', function (Request $request, Response $response, array $args) {...
我必须在路由中添加 "slim/"。
为什么?在我的另一台电脑上它工作。唯一改变的是 apache 的版本:2.3.4 和 2.3.23 请帮忙。
检查您是否将文件添加到 c:\wamp\www 您能否在本地主机上访问它,如果不能,则说明您的配置有问题。
检查两个版本是否都是准确的代码,一个版本没有像在以下任一版本中那样使用组来包装路由:discourse.slimframework。com/t/add-prefix-to-all-routes/515/4 或 slimframework。com/docs/v3/objects/router .html#route-groups
不使用组并希望从子目录支持 Slim:按照此问题评论中描述的步骤操作 github。com/slimphp/Slim/issues/1529#issuecomment-341734546 。
不明白,这不是我第一次在 slim 下启动项目,但我有一个无法解释的错误。
我的文件夹:
c:\wamp\www\slim
我创建了 "public" 文件夹
c:\wamp\www\slim\public
如文档所说,我创建了 2 个 .htaccess: 在根目录中:
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/ [L]
在 public 文件夹中:
# Redirect to front controller
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
这是我的 index.php 在 public 文件夹中:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App;
var_dump($_SERVER);
$app->get('/', function (Request $request, Response $response) {
$response->getBody()->write("Hello");
return $response;
});
$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
如果我尝试转到:http://localhost/slim/ :: 找不到页面 如果我尝试转到:http://localhost/slim/hello/Alex :: 找不到页面
只有我这样设置我的路线才有效:
$app->get('/slim/hello/{name}', function (Request $request, Response $response, array $args) {...
我必须在路由中添加 "slim/"。
为什么?在我的另一台电脑上它工作。唯一改变的是 apache 的版本:2.3.4 和 2.3.23 请帮忙。
检查您是否将文件添加到 c:\wamp\www 您能否在本地主机上访问它,如果不能,则说明您的配置有问题。
检查两个版本是否都是准确的代码,一个版本没有像在以下任一版本中那样使用组来包装路由:discourse.slimframework。com/t/add-prefix-to-all-routes/515/4 或 slimframework。com/docs/v3/objects/router .html#route-groups
不使用组并希望从子目录支持 Slim:按照此问题评论中描述的步骤操作 github。com/slimphp/Slim/issues/1529#issuecomment-341734546 。