I'm not sure what you ought to do about the custom query (you may just
have to build it the hard way or do as Ed suggest and redesign the
DB), but regarding the URL, there are a few ways to go about it.

Firstly, I should point out that the URL you wrote doesn't look right.
Usually, with something like checkboxes, you want to transmit the data
as an array:

http://mysite.com/search/results/value1[]=0&value1[]=1&value2[]=0&value2[]=1

I think that's how URL-encoded array data usually looks.

As to how to get from the standard http URL-encoding to Cake's REST-
style encoding, there are a few ways to go about it. The most obvious
way is to use JavaScript to build the Cake URL. That would be easy to
do, but it's not a good approach from an accessibility standpoint.
Instead, I would recommend accepting the "ugly" url and then, in the
controller, translate that into a Cake URL and redirect the user
there.

For example, you'd start with a standard search form with an action
url of:

http://mysite.com/search

which produces URLs like:

http://mysite.com/search?value1[]=0&value1[]=1&value2[]=0&value2[]=1...

Then the action that http://mysite.com/search routes to will take
those GET variables and convert them into:

http://mysite.com/search/result/value1:0,1/value2:0,1/...

I'm not sure if Cake has its own way of serializing arrays for URLs,
but that would seem like the most readable way to do it. You might
also try:

/search/result/value1[]:0/value1[]:1/value2[]:0/value2[]:1

or use PHP's serialize() function, which would return something like:

/search/result/value1:a:2:{i:0;i:0;i:1;i:1;}/value2:a:2:{i:0;i:0;i:1;i:
1;}

--which is not very pretty.

On Jun 4, 8:54 pm, Ed Propsner <crotchf...@gmail.com> wrote:
> Thanks Calvin, point well taken. I'll just stick with GET like I always have
> for searches.
>
> I tweaked the routing and got things cleaned up a bit so I guess I'm okay
> with it.
> I'm not quite sure what I was expecting in the first place? 8-)
>
> The search uses a lot of checkboxes and results in something 
> likehttp://mysite.com/search/results/value1=0&value1=1&value2=0&value2=1.
> I can't seem to clean it up any more when submitting with GET, or am I still
> missing something?
>
> Anyhow, at least it's working the way that I want it to. I'm still having
> some issues with query so I'll quit fussing with the url for now.
>
> - Ed
>
> On Fri, Jun 4, 2010 at 10:15 PM, calvin <cal...@rottenrecords.com> wrote:
> > POST requests are generally not cached, but you can force it to be
> > cached using the Cache-Control and Expires headers. However, I've
> > never tried this so I don't know if the browser will still show the
> > form submission dialog (it may need to resend the form data to check
> > to see if the document has changed since last requested). It probably
> > won't, but I would still strongly advise against this.
>
> > A search request is generally an idempotent operation (multiple
> > requests do not have any side-effects), which is precisely what the
> > GET request is designed for. There's no reason to use POST in this
> > case. Cake has a perfectly good way of hiding ugly URL-encoding using
> > its REST-style routing patterns, e.g.:
>
> >http://yoursite.com/pages/search/foo/bar/foo2/bar2/...
>
> > You can also use named parameters to make the search URL more
> > readable, e.g.:
>
> >http://yoursite.com/products/search/q:paegan/artist:acid+bath/categor...
>
> > Unless you have a ton of search options, I see no reason to use POST.
> > And even if you use POST and generate shorter/cleaner URL--what's the
> > point? What will that clean URL achieve? The user can't bookmark it.
> > They can't link a friend to it. They can't do anything with it.
>
> > A happy compromise would be to do what a lot of forums do, and cache
> > each search server-side. Then when the user performs a search (with
> > either POST or GET), they get redirected to the cached search result,
> > which might be something like:
>
> >http://yoursite.com/search/paegan+terrorism+tactics/f83e3a4b389c6b
>
> > That will decrease your server load, allow you to use a POST form, and
> > still allow the user to bookmark/link the search results (at least for
> > a time).
>
> > On Jun 4, 10:40 am, Ed Propsner <crotchf...@gmail.com> wrote:
> > > I was checking out the book on complex queries and not really finding
> > what
> > > I'm looking for.
>
> > > I'm trying to create a query that covers both a basic and advanced
> > search.
> > > The form may be submitting all or just some of the options available on
> > the
> > > page depending on what the user chooses.
>
> > > Once the form has been submitted clicking any one of the query results
> > would
> > > navigate the user away from the 'results page'.
>
> > > To avoid getting hit with the "form submission" dialogue when the users
> > > clicks the back button to return to the search results page
> > > and to cover the 'conditional query' ... I used to use a combo of $_GET
> > and
> > > if(isset.
>
> > > ie:
>
> > > $query= " SELECT something FROM somewhere WHERE etc. etc. etc. AND ";
>
> > >    if (isset($_GET['some_value']) && $_GET['some_value'] != '' )
> > >   {
> > > $value = $_GET['some_value'];
> > > $query .= "AND  something = '".addslashes($value)."'";
> > >   }
>
> > > And so on.
>
> > > I'm not familiar with using cache for anything. To avoid using get and
> > the
> > > ugly urls would I be able to use post and cache the results also avoiding
> > > the "form submission" dialogue when returning to the results page?
>
> > > Also, what is the best approach to setting up a 'conditional' query
> > similar
> > > to what I posted above?
>
> > > I'll spend some more time digging through the book and experimenting if
> > > someone can point me in the right direction.
>
> > > Thanks,
>
> > > - Ed
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others
> > with their CakePHP related questions.
>
> > You received this message because you are subscribed to the Google Groups
> > "CakePHP" group.
> > To post to this group, send email to cake-php@googlegroups.com
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com<cake-php%2bunsubscr...@googlegroups.com>For
> >  more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to