教程 slim 测试 $app->get(x) 报错
Tutorial slim test $app->get(x) error
在执行以下关于 Slim 的 Tutorial (9:48) 并测试 Slim 功能后,我仍然收到 "Page not found"。
程序应该回显在某个点 eg.If 搜索“http://localhost/authentication/public/test/Hello”后在搜索栏中键入的任何词,页面应该回显 'Hello',页面应该回声'Hello'.
这是通过使用 .htaccess 文件将任何 link 重新路由到 index.php 来完成的。 index.php 文件然后运行名为 start.php.
的 php 文件
关于为什么这可能不起作用的任何建议?
苗条v3.x
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
index.php
<?php
require '../app/start.php';
$app->run();
?>
start.php
<?php
use Slim\App;
session_cache_limiter(false);
session_start();
ini_set('display_errors', 'On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new App();
$app->get('/test/:name', function($name) {
echo "Hello! {$name}";
});
?>
问题是您在使用 Slim 3 时尝试使用 Slim 2 代码。
您必须将代码更改为新结构或切换回 v2。
上有一个像你这样的例子
//example taken from slimframework.com
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
我建议通读 official docs。
在执行以下关于 Slim 的 Tutorial (9:48) 并测试 Slim 功能后,我仍然收到 "Page not found"。
程序应该回显在某个点 eg.If 搜索“http://localhost/authentication/public/test/Hello”后在搜索栏中键入的任何词,页面应该回显 'Hello',页面应该回声'Hello'.
这是通过使用 .htaccess 文件将任何 link 重新路由到 index.php 来完成的。 index.php 文件然后运行名为 start.php.
的 php 文件关于为什么这可能不起作用的任何建议?
苗条v3.x
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
index.php
<?php
require '../app/start.php';
$app->run();
?>
start.php
<?php
use Slim\App;
session_cache_limiter(false);
session_start();
ini_set('display_errors', 'On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new App();
$app->get('/test/:name', function($name) {
echo "Hello! {$name}";
});
?>
问题是您在使用 Slim 3 时尝试使用 Slim 2 代码。 您必须将代码更改为新结构或切换回 v2。
上有一个像你这样的例子//example taken from slimframework.com
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
我建议通读 official docs。