0


I am trying to construct url which looks like this:

 abc.com/folder?user_id=1&category=v

Followed the suggestion given in this link:

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

Initially, it throws up this error

 Query route deprecated as of ZF 2.1.4; use the "query" option of the HTTP router\'s assembling method instead

Following suggestion, I used similar to

  $name    = 'index/article';
  $params  = ['article_id' => $articleId];
  $options = [
    'query' => ['param' => 'value'], 
  ];
  $this->url($name, $params, $options);

Now, I am getting syntax error saying,

   Parse error: syntax error, unexpected '[' in /var/www/test/module/Dashboard/view/dashboard/dashboard/product.phtml on line 3

My module.config.php is configured like this:

   'browse_test_case' => array(
                        'type' => 'Literal',
                        'options' => array(
                            'route' => '/browse-case[/:productId]',
                            'defaults' => array(
                                'controller' => 'Test\Controller\Browse',
                                'action'     => 'browse-test-case',
                            ),
                        ),
                        'may_terminate' => true,
                        'child_routes'  => array(
                            'query' => array(
                                'type' => 'Query',
                            ),
                        ),
                        ),

Any Idea, please help!

Community
  • 1
  • 1
notnotundefined
  • 3,493
  • 3
  • 30
  • 39

1 Answers1

0

Your url view helper call is wrong. First parameter is the name of a defined route, second parameter is an array with your route parameters. Your array syntax should also be correct. e.g. array("param1" => "value1", "param2" => "value2")

In your example the correct url view helper call should be something like this: $this->url('browse_test_case', array('productId' => '1'));

...in which "1" could be an database table row identifier, for example.

The Query child-route in your route definition, allows you to use also other url paramaters, than specified within the route. But each of these child-routes start with "/browse-case[/:productId]".

There you find the reference example of ZF2: http://framework.zend.com/manual/2.3/en/modules/zend.view.helpers.url.html#zend-view-helpers-initial-url

Achim
  • 302
  • 2
  • 5