Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Silverstripe$url\u处理程序不工作-运行方法,但也会触发404错误_Php_Routing_Silverstripe - Fatal编程技术网

Php Silverstripe$url\u处理程序不工作-运行方法,但也会触发404错误

Php Silverstripe$url\u处理程序不工作-运行方法,但也会触发404错误,php,routing,silverstripe,Php,Routing,Silverstripe,我的控制器的$url\u处理程序不工作。已定义的方法调用成功,但也会触发404 编辑:为上下文添加了$allowed\u操作(谢谢) 示例代码: class MyPage_Controller extends Page_Controller { . . . private static $allowed_actions = array( 'test' ); private static $url_handlers = array(

我的控制器的$url\u处理程序不工作。已定义的方法调用成功,但也会触发404

编辑:为上下文添加了$allowed\u操作(谢谢)

示例代码:

class MyPage_Controller extends Page_Controller {

    . . .

    private static $allowed_actions = array(
        'test'
    );

    private static $url_handlers = array(
        'view/$ID/test/' => 'test'
    );

    . . .
注意:URL的静态部分
/test

行动:

class MyPage_Controller extends Page_Controller {

    . . .

    public function test() {
        var_dump($this->getRequest()->param('ID'), $this->getAction());
        return $this;
    }

    . . .
这导致404模板显示在var_dump输出下面(使用URL
//view/2/test/
):


在Silverstripe 3.5.1中测试,从URL模式中删除尾部的
/

private static $url_handlers = array(
    'view/$ID/test' => 'test'
);

HTTPRequest::match()
检查模式时,它使用
explode('/',$pattern)
将其分离。额外的
/
会在
RequestHandler::handleRequest()
稍后验证URL中是否遇到了模式的所有部分(通过调用
HTTPRequest::allParsed()
)时导致差异,因此它也会返回
404

,不要
返回$this
-控制器操作应该返回一个
SS_HTTPResponse
文档允许使用尾随斜杠进行路由,我想知道SilverStripe是否真的对$url_处理程序有问题?文档的示例中没有它们。。。您的操作是否在$allowed\u actions数组中进行“测试”?看见
private static $url_handlers = array(
    'view/$ID/test' => 'test'
);