我不明白,这不是我第一次在 slim 下启动项目,但我有一个无法解释的错误。
我的文件夹:
c:\wamp\www\slim
我创建了“公共”文件夹
c:\wamp\www\slim\public
就像文档说的那样,我创建了 2 个 .htaccess:在 root 中:
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
在公共文件夹中:
# Redirect to front controller
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
这里是我在公共文件夹中的 index.php:
<?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/ :: Page not found 如果我尝试去:http://localhost/slim/hello/Alex :: Page not found
只有当我这样设置我的路线时它才有效:
$app->get('/slim/hello/{name}', function (Request $request, Response $response, array $args) {...
我必须在路由中添加“slim/”。
为什么?在我的另一台电脑上它可以工作。唯一改变的是apache的版本:2.3.4和2.3.23请帮忙。
检查您是否将文件添加到 c:\wamp\www 是否可以在 localhost 上访问它,如果不能,则说明您的配置有问题。
检查两个版本是否都是确切的代码,一个没有使用组来包装路由,因为它们在以下任一版本中: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。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句