phpzend-framework3post-redirect-get

How do i correctly redirect in Zend Framework 3?


I have a controller with the following Code to display a list which can be searched and filtered:

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

The Get-Requests are working correctly and my page loads within a few ms. But when posting data the page loads for ~5 Minutes. After that it will eventually redirect and show the correct page too.

The strange thing is, that the code is working on some machines, but on others the post -> redirect runs for ~5 minutes. The machines have the same OS and browser builds installed.

Am i using the redirect wrongly ?


Solution

  • you need to add return

    so try:

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