如何在Zend Framework 3中正确重定向?

时间:2018-11-12 11:26:14

标签: php zend-framework3 post-redirect-get

我有一个带有以下代码的控制器来显示可以搜索和过滤的列表:

public function listAction() {

    if($this->getRequest()->isPost()) {
        $post = array_filter($this->getRequest()->getPost()->toArray(), function($value) {
            return ($value !== null && $value !== false && $value !== ''); 
        });
        $this->redirect()->toRoute('myRoute/list', $post);
    }
    $filter = $this->params()->fromRoute();
    // Get correct Data and display as list
}

myRoute:

'myRoute' => [
            'type' => Literal::class,
            'options' => [
                'route'    => '/myRoute',
                'defaults' => [
                    'controller' => Controller\MyController::class,
                    'action'     => 'index',
                ],
            ],
            'may_terminate' => false,
            'child_routes' => [
                'list' => [
                    'type' => Segment::class,
                    'options' => [
                        'route'    => '/list[/page/:page][/search/:search][/type/:type]',
                        'defaults' => [
                            'controller' => Controller\MyController::class,
                            'action'     => 'list',
                            'page'       => 1
                        ],
                    ],
                ],
... other routes

Get-Requests正常运行,我的页面在几毫秒内加载。但是,当发布数据时,页面将加载约5分钟。之后,它将最终重定向并显示正确的页面。

奇怪的是,代码在某些机器上运行,但是在其他机器上,post->重定向运行了大约5分钟。这些机器安装了相同的操作系统和浏览器版本。

我错误地使用了重定向吗?

1 个答案:

答案 0 :(得分:0)

您需要添加return

所以尝试:

 return $this->redirect()->toRoute('myRoute/list', $post);