On Tuesday, July 12, 2016 at 9:46:22 AM UTC-4, Carlos Cesar Caballero wrote:
>
> Hi Anthony, unfortunately the parameter-based router doesn't suit my 
> needs, I need (among other things) the ability to map urls in that way:
>
> www.mysite.com/cuba to www.mysite.com/app/country/index/cuba
> www.mysite.com/cuba/cienfuegos to 
> www.mysite.com/app/state/index/cuba/cienfuegos
> www.mysite.com/cuba/cienfuegos/one_place to 
> www.mysite.com/app/places/index/cuba/cienfuegos/one_place
>
> or
>
> www.mysite.com/cuba to www.mysite.com/app/country/index?country=cuba
> www.mysite.com/cuba/cienfuegos to 
> www.mysite.com/app/city/index?country=cuba&city=cienfuegos
> www.mysite.com/cuba/cienfuegos/one_place
> to 
> www.mysite.com/app/places/index?country=cuba&city=cienfuegos&place=one_place
>
> We have done this before (including url-based internationalization) with 
> the yii2 framework router, but it is being a little difficult with web2py.
>

Unless you have some other more complex URL requirements, I think you might 
be overcomplicating things by constraining yourself to have separate 
controllers for country, city, and place (why bother with separate 
controllers if each just uses a single index function?). Instead, why not 
route everything to a single controller action, and branch out from there 
depending on the case. For example:

In default.py:

def index():
    if request.args(2):
        return place(request.args)
    elif request.args(1):
        return city(request.args)
    else:
        return country(request.args(0))

def country(country):
    response.view = 'default/country.html'
    ...
    return dict(...)

def city(location):
    response.view = 'default/city.html'
    country, city = location
    ...
    return dict(...)

def place(location):
    response.view = 'default/place.html'
    country, city, place = location
    ...
    return dict(...)

Now you can use the parameter-based router as follows:

routers = dict(
    BASE=dict(
        default_application='yourapp',
        default_controller='default',
        default_function='index',
        functions=['index', 'user', 'other', 'functions', 'in', 'default', 
'controller'],
        languages=['es', 'fr', 'en', 'it'],
        default_language='es'
    ),
)

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to