Note that there are some explanatory texts on larger screens.

plurals
  1. POurlencode() error when using Zend_Controller_Router_Route and URL view helper
    primarykey
    data
    text
    <p>I am using the standard router in Zend Framework to route most URLs in the system.</p> <p>For one particular URL, I want to access it via a controller alias (in addition to the real controller)</p> <p>For example.</p> <p>Actual URL:</p> <pre><code>/mymodule/mycontroller/myaction/* </code></pre> <p>Alias URL:</p> <pre><code>/mymodule/mycontrolleralias/myaction/* </code></pre> <p>mycontrolleralias is not a real controller, but I want any requests to it to route to mycontroller (query params and all)</p> <p>To do this, I have tried to setup this route:</p> <pre><code>$router-&gt;addRoute('controlleralias', new Zend_Controller_Router_Route( ':module/mycontrolleralias/:action/*', array( 'module' =&gt; 'mymodule', 'controller' =&gt; 'mycontroller', 'action' =&gt; 'myaction' ) )); </code></pre> <p>But in my view helper if I try to create a URL:</p> <pre><code>$this-&gt;view-&gt;url(array('sort' =&gt; array('param1','param2'))); </code></pre> <p>I get an error:</p> <pre><code>urlencode() expects parameter 1 to be string, array given #0 [internal function]: __lambda_func(Array) #1 /library/Zend/Controller/Router/Route.php(398): urlencode(Array, false, true) #2 /library/Zend/Controller/Router/Rewrite.php(441): Zend_Controller_Router_Route-&gt;assemble(Array, NULL, false, true) #3 /library/Zend/View/Helper/Url.php(49): Zend_Controller_Router_Rewrite-&gt;assemble(Array) </code></pre> <p>If I remove the star (*) from my custom route, no error will occur - but the urls generated in my view are then not correct because they will not be matching the query parameters:</p> <pre><code>$router-&gt;addRoute('controlleralias', new Zend_Controller_Router_Route( ':module/mycontrolleralias/:action', array( 'module' =&gt; 'mymodule', 'controller' =&gt; 'mycontroller', 'action' =&gt; 'myaction' ) )); </code></pre> <p>I have also found that if I <strong>don't</strong> pass in an array for a parameter, it will <strong>not</strong> generate an error:</p> <pre><code>$this-&gt;view-&gt;url(array('sort' =&gt; 'param1')); </code></pre> <p>Unfortunatly I do need to pass in an array for 'sort' (as shown above)</p> <p>Does anyone know what I'm doing wrong? Perhaps there is an easier way to achieve this?</p> <p>I am using Zend Framework 1.9.0</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload