开发者

Generating URL with URL view helper, passing params after?

Is there easy way how to generate url using view url helper in format where custom params (except controller and action) will be after "?" ?

There is example:

<?php echo $this->url(array('controller' => "index", 'action' => "index", 'myParam' => "myValue")); ?>

This will generate:

domain.com/index/index/myParam/myValue

I want

domain.com?myParam=myValue or

dom开发者_开发百科ain.com/{controller}/{action}?myParam=myValue


You can use the reverse field of a Regex route for example :

   $myroute = new Zend_Controller_Router_Route_Regex('\?myParam=(.*)',
                    array(1 => 'defaultValue', 'controller' => 'index', 'action' => 'index', 'module' => 'index'),
                    array(1 => 'myValue'),
                    '?myParam=%s'
    );

   $wwwDomainRoute = new Zend_Controller_Router_Route_Hostname(
                    'www.domain.com');

   $plainPathRoute = new Zend_Controller_Router_Route_Static('');

   //this default route is useful for the default routing
   $router->addRoute('wwwroute', $wwwDomainRoute->chain($plainPathRoute));
   $router->addRoute('myroute', $wwwDomainRoute->chain($myroute));

and in your view just use :

   <?php echo $this->url(array('controller' => "index", 'action' => "index", 'myParam' => "myValue"),'myroute'); ?>

note : be careful with your regex...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜