-- Matt Pearson <[email protected]> wrote
(on Friday, 26 June 2009, 12:36 PM +0100):
> I have a problem with GET forms submitting to controllers within the
> framework.
> 
> I have a GET form in a page outside of the Zend Framework app. It does a
> normal GET to the search controller of my Framework app like this (I
> have a custom route set up)
> 
> /app/search?q=query
> 
> However, my search controller can't get a value for 'q' and the custom
> routes all seem to strip off the portion of the url after the '?' !

Within your controller, you have a couple of different ways to retrieve
this value:

  * via _getParam: $this->_getParam('q'). This actually proxies to the
    request object's getParam() method, which searches first for
    parameters matched on the route, then GET, then POST.

  * via the request object's getQuery() method:
    $this->getRequest()->getQuery('q');

> How do I get routes like Zend_Controller_Router_Route_Regex to use the
> portion after the '?'

You don't. You'll have to do one of two things:

  * Extend the Regex route to merge $_GET parameters into the array of
    matched parameters

  * Create a RewriteCond to match the query string and rewrite the URL:
    
    RewriteCond %{query_string} ^q=([^&]*)$
    RewriteRule ^/?app/search  /app/search/q/%1

    Note that I haven't tested the above, but the idea is that it
    searches for a "q" parameter in URLs with /app/search, and then
    rewrites the url to add it into the URL itself.


> I have tried disabling all my routes and using the 'real' Framework
> path. This works:
> 
> /app/search/index/results?q=query
> 
> But then I have the problem that my Zend Paginator links become things
> like:
> 
>  /app/search/index/results/page/1
> 
> Which doesn't work, because it omits the search query.
> 
> When URIs are in /proper/framework/format everything is fine. I've seen
> people use Javascript to get around this problem, but I don't want to
> make my site Javascript dependent.
> 
> Can anyone help? I'm sure there is something obvious that I'm doing
> wrong.
> 
> For full disclosure; here are my Apache rules:
> 
> RewriteCond %{REQUEST_FILENAME} !-f[OR]
> RewriteCond %{REQUEST_FILENAME} !-d
>  
> RewriteRule ^/app/(.*) /app.php?$1 [L]
> 
> (My front controller defines /app as the BaseUrl)

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to