作为这个问题的前言,我正在转换一个演示应用程序,以使用RESTful,SEO友好的URL;除了用于AJAX请求的两个路由中的一个之外,所有的路由在用于web上的应用程序时都可以工作,并且所有的路由都使用Postman进行了完整的测试-使用一个普通的Nginx配置。
也就是说,下面是违规的路由定义-登录是失败的已定义路由:
$routing_map->post('login.read', '/services/authentication/login', [
'params' => [
'values' => [
'controller' => '\Infraweb\Toolkit\Services\Authentication',
'action' => 'login',
]
]
])->accepts([
'application/json',
]);
$routing_map->get('logout.read', '/services/authentication/logout', [
'params' => [
'values' => [
'controller' => '\Infraweb\Toolkit\Services\Authentication',
'action' => 'logout',
]
]
])->accepts([
'application/json',
]);使用Postman & xdebug跟踪,我认为它(显然)没有通过我认为的路径规则中的REGEX检查,但我不能完全理解它。至少可以说是令人沮丧的。在这里发帖之前,我使用网络搜索寻找了所有我能找到的地方--谷歌的Auraphp群组最近似乎没有多少流量。可能我做错了什么,所以我想是时候向集体用户社区寻求一些方向了。任何和所有建设性的批评都是非常欢迎和赞赏的。
提前感谢,很抱歉在这个问题上浪费了任何人的带宽…
发布于 2019-02-25 14:00:33
让我把话说清楚。Aura.Router不做分派。它只与路由匹配。它不会处理您的路由是如何处理的。
查看完整的working example (在该示例中,假设处理程序是可调用的)
$callable = $route->handler;
$response = $callable($request);在您的情况下,如果您匹配请求(请参阅matching request )
$matcher = $routerContainer->getMatcher();
$route = $matcher->match($request);您将获得路由,现在您需要编写适当的方法来处理来自$route->handler的值。
这是我在var_dump /signin路由的$route->handler之后所做的事情。
array (size=1)
'params' =>
array (size=1)
'values' =>
array (size=2)
'controller' => string '\Infraweb\LoginUI' (length=17)
'action' => string 'read' (length=4)下面尝试了完整的代码。正如我之前提到的,我不知道你的路由处理逻辑。所以这是由你来决定是否正确地写东西。
<?php
require __DIR__ . '/vendor/autoload.php';
use Aura\Router\RouterContainer;
$routerContainer = new RouterContainer();
$map = $routerContainer->getMap();
$request = Zend\Diactoros\ServerRequestFactory::fromGlobals(
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);
$map->get('application.signin.read', '/signin', [
'params' => [
'values' => [
'controller' => '\Infraweb\LoginUI',
'action' => 'read',
]
]
]);
$map->post('login.read', '/services/authentication/login', [
'params' => [
'values' => [
'controller' => '\Infraweb\Toolkit\Services\Authentication',
'action' => 'login',
]
]
])->accepts([
'application/json',
]);
$matcher = $routerContainer->getMatcher();
// .. and try to match the request to a route.
$route = $matcher->match($request);
if (! $route) {
echo "No route found for the request.";
exit;
}
echo '<pre>';
var_dump($route->handler);
exit;根据记录,这是composer.json
{ "require":{ "aura/router":"^3.1","zendframework/zend-diactoros":"^2.1“}}
和运行方式
php -S localhost:8000 index.php和浏览http://localhost:8000/signin
https://stackoverflow.com/questions/54819407
复制相似问题