Hi Everyone,

Thanks for your help. As it turns out, I was doing more than one thing
wrong, but Matthew mentioning getQuery() put me on the right track.

The Framework app that I'm working sits inside a non-framework app,
therefore much of this is specific to the environment I'm working in.
Just in case its any help to anyone else. Here is what I did.

I noticed app.php getting odd URIs like this:

app.php?app/search?q=search+word

This was causing the GET vars from the request to disappear, so I
modified my rewrite rule as follows:

RewriteRule ^/app/(.*) /app.php?$1 [L]

Became:

RewriteRule ^/app/(.*)$ /app.php?%{REQUEST_FILENAME}&%{QUERY_STRING} [L]


I changed my controller to read from getQuery() as well as getParam(),so
that I could read the value of q whichever way it came through.

I then modified the calls to the URL helper in the view to sort out the
Paginator links.

Thanks again

Matt


-----Original Message-----
From: Matthew Weier O'Phinney [mailto:[email protected]] 
Sent: 26 June 2009 13:04
To: [email protected]
Subject: Re: [fw-general] Coping with Old-style GET vars.

-- 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/


Work with the environment... think before you print

Liz Earle Naturally Active Skincare 
The Green House  Ryde IOW  PO33 1BD

Telephone +44 (0)1983 813913. Fax +44 (0)1983 813912. 
Email [email protected] <mailto:[email protected]>  Web 
www.lizearle.com <http://www.lizearle.com> 
Liz Earle Naturally Active Skincare is a trading name of Liz Earle Beauty Co. 
Limited.
Registered in England No. 3070395 Registered address: 5 Fleet Place, London,  
EC4M 7RD.

Reply via email to