Search code examples
zend-frameworkzend-route

how to keep 'index' param when call url helper in zend


When I tried to call url helper in a view file like below:

$url = $this->url();

The result is if:

  1. At current the controller is index and action is index. With index is default action key, it will be only out:
    [base_url]\[module]
  2. At current the controller is not index and action is no tindex it will only out:
    [base_url]\[module]\[controller]\action

But I want the link in 1st case is:

[base_url]\[module]\index\index

How can I get it?


Solution

  • If you pass a param to url helper you will retrive a full url for 1st case.

    For example:

    in index.phtml

    <?php
     echo $this->url(array('test'=>'test'));
    ?>
    

    It will print out:

    /[root]/public/[module]/[controller]/index/test/test 
    

    The you can get index action, and you've just ignore the /test/test

    <?php
     $url  = $this->url(array('test'=>'test'));
     echo substr($url,0,-10);
    ?>
    

    Output:

    /[folder]/public/[module]/[controller]/index