【发布时间】:2019-06-07 22:57:05
【问题描述】:
我在我的 Cakephp3 中使用 TinyAuth 插件。我有一个具有以下命名空间的控制器:
namespace App\Controller\Api\Datatables;
控制器是Listings,我的功能是Filter
我有以下路线设置:
Router::scope('/datatables', ['prefix' => 'api/datatables'], function (RouteBuilder $routes) {
$routes->extensions(['json', 'xml', 'ajax']);
$routes->fallbacks(DashedRoute::class);
});
这允许我调用以下网址:
/datatables/listings/filter.json
我要允许过滤功能:
datatables/Listings = filter
当我调用我的 URL 时,我被重定向到登录。如果我登录 url 有效,那么 allow_auth 有效。
我还尝试了以下方法:
api/datatables/Listings = filter
api/Datatables/Listings = filter
Api/Datatables/Listings = filter
api/datatables/Listings = filter
datatables/Listings = filter
Datatables/Listings = filter
api/Listings = filter
不管是什么路径都是不允许的。如果我将控制器移动到默认位置,那么在 allow_auth 中:
Listings = filter
过滤功能无需授权即可访问。这表明在使用路由器作用域时插件存在问题。
这是插件的composer.json
{
"name": "ypnos-web/cakephp-datatables",
"description": "jQuery DataTables for CakePHP 3",
"homepage": "https://github.com/ypnos-web/cakephp-datatables",
"type": "cakephp-plugin",
"keywords": ["cakephp", "datatables"],
"license": "MIT",
"authors": [
{
"name": "Frank Heider",
"homepage": "https://github.com/fheider",
"role": "Author"
},
{
"name": "Johannes Jordan",
"homepage": "https://github.com/ypnos-web",
"role": "Author"
}
],
"require": {
"php": ">=7.0",
"cakephp/cakephp": "^3.6"
},
"autoload": {
"psr-4": {
"DataTables\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"DataTables\\Test\\": "tests",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
}
}
}
我是否正确地说斜线路由确实适用于 acl.ini - 据我所知,它们似乎是正确的。
我正在使用斜线来更好地组织我的功能。
我调用/datatables/listings/filter.json时的请求参数如下?
'controller' => 'Listings',
'action' => 'filter',
'pass' => [],
'prefix' => 'api/datatables',
'plugin' => null,
'_ext' => 'json',
'_matchedRoute' => '/datatables/:controller/:action/*',
'?' => [
'string' => 'seat'
]
如果我调用 /api/datatables/listings/filter.json:
找不到控制器类数据表。
【问题讨论】:
-
我很好奇$this->request->params包含什么,这里的路由数组里到底是什么数据?这才是最重要的,而不是您的命名空间(PHP 内部)或斜杠前缀(公共 URL 内部)
-
@mark 我应该在哪里调试我的请求参数?
-
在您尝试调试的控制器内部,以及在 initialize() 等内部无法访问的地方
-
请查看我更新的参数问题
标签: authentication cakephp cakephp-3.x