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
How to Extend a Class Dynamically
MySQL Join Multiple Rows as Columns
How to Find Array/Dictionary Value Using Key
Return Errors from PHP Run Via. Ajax
Get the Price of an Item on Steam Community Market with PHP and Regex
How to Set Current Page "Active" in PHP
How to Store JavaScript Variable Output into a PHP Variable
PHP How to Create Multiple Sessions
Using Ajax in a Wordpress Plugin
How to Connect PHP with Microsoft Access Database
Use a Variable Within Heredoc in PHP
Wordpress Plugin -> Call to Undefined Function Wp_Get_Current_User()
PHP MySQL - Insert New Record into Table with Auto-Increment on Primary Key
Why Does PHP Allow "Incompatible" Constructors