How to Add Query Parameters in the Zf2/Zf3 Url View Helper

How can you add query parameters in the ZF2 / ZF3 url view helper

You can create a child route for your users route like this:

'users' => array(
'type' => 'Literal',
'options' => array(
'route' => '/users',
'defaults' => array(
'__NAMESPACE__' => 'User\Controller',
'controller' => 'Index',
'action' => 'list',
),
),
'may_terminate' => true,
'child_routes' => array(
'query' => array(
'type' => 'Query',
),
),
),

then you can assemble $this->url('users/query', array('sort' => 'desc')).

Don't forget to set may_terminate to true!

ZF2 Create route like login?url=foo

I don't think you should put your query string segment in your route. It would seem reasonable to have your route to be just /login and then manage your query string parameter in the controller.

Otherwise, but I don't recommend it since it is deprecated, you could try to use the Query router.

How to add parameters to controller redirect?

In the end, what I did was, instead of using route parameters, using query parameters, since the parameters I used where not route related. That solved the problem.

How to get GET and POST parameters in view in Zend Framework 3?

I assume that it is the same as ZF2, passing them to the view.

    $viewModel = new ViewModel();
$viewModel->my_get_var = $this->params()->fromQuery('my_get_var', 'default_value');
$viewModel->my_post_var = $this->params()->fromPost('my_post_var', 'default_value');
return $viewModel;

You can then display them in your view.phtml

<?php echo $this->my_get_var; ?>
<?php echo $this->my_post_var; ?>

See my answer here.



Related Topics



Leave a reply



Submit