1
votes

I looked around to find answers and though I found topics about the routes, none of the answers I found worked in this case. So here I go, trying to explain my problem =]

Background information

I'm making a website in Cakephp for an estate agent. On this website you have the possibility to sort houses based on the street, publish date and price.

What I want

I want to change these current urls:
websitename.nl/houses/index/page:4/sort:street/direction:desc
websitename.nl/houses/index/sort:street/direction:desc/page:4

to something like:
websitename.nl/houses/street/descending/4
websitename.nl/houses/price/ascending/4

Street/price and descending/ascending will be translated to dutch.

What I already tried

I tried to add this in routes.php:

Router::connect('/huizenaanbod/datum/aflopend/:page', array('controller' => 'houses', 'action' => 'index', 'sort'=>'published', 'direction' => 'desc'), array('page' => '[0-9]+'));
Router::connect('/huizenaanbod/datum/oplopend/:page', array('controller' => 'houses', 'action' => 'index', 'sort'=>'published', 'direction' => 'asc'), array('page' => '[0-9]+')); 

But it ignored the desc and only the asc worked.. So I tried to add this at the index.ctp:

if((!empty($this->params['sort']) && $this->params['sort'] == "published") && $this->params['direction'] == 'desc'){
    echo $this->Paginator->sort('published', 'datum', array('direction' => 'asc', 'escape' => false));
} else {
    echo $this->Paginator->sort('published', 'datum', array('direction' => 'desc', 'escape' => false));
}

And eventhough the url does change now, the results of the sort are still ordered ASC.

So my question is:
How can I make an url in routes, combined with :page, for a specific sort and direction?

If you need more information, let me know.

And thank you in advance =]

1

1 Answers

0
votes

you better look at other web agencies web site to see how they do the filtering. look at the link below see how the parameters is passed.. e.g.

http://www.rightmove.co.uk/property-for-sale/find.html?searchType=SALE&locationIdentifier=REGION%5E92826&insId=1&radius=0.0&displayPropertyType=&minBedrooms=&maxBedrooms=3&minPrice=&maxPrice=&retirement=&partBuyPartRent=&maxDaysSinceAdded=&_includeSSTC=on&sortByPriceDescending=&primaryDisplayPropertyType=&secondaryDisplayPropertyType=&oldDisplayPropertyType=&oldPrimaryDisplayPropertyType=&newHome=&auction=false

Now lets get back to you question.. for passing all the parameters you need to use /** e.g.

Router::connect(
    '/action_name/**', //once you requesting rather than star you need to put your parameters 
    array('controller' => 'pages', 'action' => 'show')
);
//www.exsmple.com/action_name/parameters here...

Reference

you can also customize your pagination class from here