One problem

resources.router.routes.myroute.route =
"my-controller/price/:price/year/:year/city/:city/sort/:sort"
resources.router.routes.myroute.defaults.module = "default"
resources.router.routes.myroute.defaults.controller = "my-controller"
resources.router.routes.myroute.defaults.action = "index"
resources.router.routes.myroute.defaults.price = 100
resources.router.routes.myroute.defaults.year = 2000
resources.router.routes.myroute.defaults.city = 0
resources.router.routes.myroute.defaults.sort = 0

this works as expected as long as I don't skip any param from the route. But
when I try to visit ex my-controller/price/90-600/year/1-5/city/0 I get
Zend_Controller_Action_Exception: Action "price" does not exist and was not
trapped in __call()
it searches for price action. How can I fix this? I want all params to be
optional.

Regards,
Saša Stamenković


On Tue, May 25, 2010 at 8:20 AM, Саша Стаменковић <umpir...@gmail.com>wrote:

> Thats ok, but can this minPrice and maxPrice be price array?
>
> If not, then explode in controller is handier.
>
> Regards,
> Saša Stamenković
>
>
>
> On Tue, May 25, 2010 at 12:36 AM, Hector Virgen <djvir...@gmail.com>wrote:
>
>> Or you can use a regex route. Might be easier with less code in your
>> action:
>>
>> resources.router.routes.search.type = "Zend_Controller_Router_Route_Regex"
>> resources.router.routes.search.route =
>> "search/price/(\d+)-(\d+)/year/(\d{4})-(\d{4})"
>> resources.router.routes.search.defaults.controller = "products"
>> resources.router.routes.search.defaults.action = "search"
>> resources.router.routes.search.map.1 = "minPrice"
>> resources.router.routes.search.map.2 = "maxPrice"
>> resources.router.routes.search.map.3 = "minYear"
>> resources.router.routes.search.map.4 = "maxYear"
>> resources.router.routes.search.reverse = "search/price/%s-%s/year/%s-%s"
>>
>> --
>> Hector
>>
>>
>>
>> On Mon, May 24, 2010 at 3:18 PM, Саша Стаменковић <umpir...@gmail.com>wrote:
>>
>>> Yes, I must explode them manually. Thanks.
>>>
>>> Regards,
>>> Saša Stamenković
>>>
>>>
>>>
>>> On Mon, May 24, 2010 at 10:13 PM, Hector Virgen <djvir...@gmail.com>wrote:
>>>
>>>> If your min/max price comes in as a single parameter with a hyphen
>>>> between the two values, you can use explode() to get the individual parts:
>>>>
>>>> $price = $this->_request->getParam('price');
>>>> $priceParts = explode('-', $price);
>>>> $priceMin = $priceParts[0];
>>>> $priceMax = $priceParts[1];
>>>>
>>>> --
>>>> Hector
>>>>
>>>>
>>>>
>>>> On Mon, May 24, 2010 at 1:07 PM, Bradley Holt <
>>>> bradley.h...@foundline.com> wrote:
>>>>
>>>>>
>>>>> On Mon, May 24, 2010 at 3:58 PM, Саша Стаменковић 
>>>>> <umpir...@gmail.com>wrote:
>>>>>
>>>>>> Ok, but I neeed that dash search/price/100-200/...
>>>>>>
>>>>>>
>>>>> Why does it have to be a dash? Why can't you use a forward slash? If it
>>>>> must be a dash then you have a couple of options. One is to parse the
>>>>> parameter manually in your controller by removing the dash and pulling out
>>>>> the two values. The other option is to write your own router that 
>>>>> understand
>>>>> dashes, not just forward slashes, as a separator of keys and/or values. 
>>>>> Zend
>>>>> Framework's routing functionality as-is will not be able to understand the
>>>>> dashes as being anything other than part of your data.
>>>>>
>>>>>
>>>>>> Regards,
>>>>>> Saša Stamenković
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Mon, May 24, 2010 at 9:55 PM, Bradley Holt <
>>>>>> bradley.h...@foundline.com> wrote:
>>>>>>
>>>>>>> On Mon, May 24, 2010 at 3:50 PM, Саша Стаменковић <
>>>>>>> umpir...@gmail.com> wrote:
>>>>>>>
>>>>>>>> Thanks Bradley.
>>>>>>>>
>>>>>>>> yes, thats the default routing. It accepts
>>>>>>>> /search/price/0/price/100000/year/1960/year/2010/city/0/sort_by/0/mode/1
>>>>>>>>  and
>>>>>>>> then price is an arrray in request. I want that behaviour, but just 
>>>>>>>> with a
>>>>>>>> bit prettyer url /search/price/0-100000/year/1960-2010...
>>>>>>>>
>>>>>>>>
>>>>>>> Try this, then:
>>>>>>>
>>>>>>>
>>>>>>> search/price/100/200/year/1947/2010/city/Nis/sort_by/sth/mode/1
>>>>>>>
>>>>>>>
>>>>>>> search/price/:price_min/:price_max/year/:year_min/:year_max/city/:city/sort_by/:sort_by/mode/:mode
>>>>>>>
>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Saša Stamenković
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Mon, May 24, 2010 at 9:46 PM, Bradley Holt <
>>>>>>>> bradley.h...@foundline.com> wrote:
>>>>>>>>
>>>>>>>>> On Mon, May 24, 2010 at 3:39 PM, Саша Стаменковић <
>>>>>>>>> umpir...@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> I need route like this
>>>>>>>>>>
>>>>>>>>>> search/price/100-200/year/1947-2010/city/Nis/sort_by/sth/mode/1
>>>>>>>>>>
>>>>>>>>>> search/price/:price-:price/year/:year-:year/city/:city/sort_by/:sort_by/mode/:mode
>>>>>>>>>>
>>>>>>>>>> This end up with uncaught exception
>>>>>>>>>> 'Zend_Controller_Router_Exception' with message 'price-:price is not
>>>>>>>>>> specified'.
>>>>>>>>>>
>>>>>>>>>> Can I achieve that this range 100-200 be in request like
>>>>>>>>>> array(100, 200), if not, I'll be satisfied with "100-200".
>>>>>>>>>>
>>>>>>>>>> Can someone suggest best practices for building such routes?
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I'm pretty sure you can only have one parameter per URL segment.
>>>>>>>>> Your ":price-:price" and ":year-:year" segments are trying to cram two
>>>>>>>>> parameters into one segment. Try the following instead:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> search/price-min/100/price-max/200/year-min/1947/year-max/2010/city/Nis/sort_by/sth/mode/1
>>>>>>>>>
>>>>>>>>> search/price-min/:price_min/price-max/:price_max/year-min/:year_min/year-max/:year_max/city/:city/sort_by/:sort_by/mode/:mode
>>>>>>>>>
>>>>>>>>> Actually, if you do that then you don't need to explicitly define
>>>>>>>>> your route at all since you're simply using key/value pair.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>> Saša Stamenković
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>

Reply via email to