Hi Anthony, thanks for your suggestion, but I have more requeriments for the controllers and they will grow up, I think that your suggestion solves the problem, but in my case, the software will become dificult to maintain or extend in the future.

Greetings.

El 12/07/16 a las 15:02, Anthony escribió:
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 <http://www.mysite.com/cuba> to
    www.mysite.com/app/country/index/cuba
    <http://www.mysite.com/app/country/index/cuba>
    www.mysite.com/cuba/cienfuegos
    <http://www.mysite.com/cuba/cienfuegos> to
    www.mysite.com/app/state/index/cuba/cienfuegos
    <http://www.mysite.com/app/state/index/cuba/cienfuegos>
    www.mysite.com/cuba/cienfuegos/one_place
    <http://www.mysite.com/cuba/cienfuegos/one_place> to
    www.mysite.com/app/places/index/cuba/cienfuegos/one_place
    <http://www.mysite.com/app/places/index/cuba/cienfuegos/one_place>

    or

    www.mysite.com/cuba <http://www.mysite.com/cuba> to
    www.mysite.com/app/country/index?country=cuba
    <http://www.mysite.com/app/country/index?country=cuba>
    www.mysite.com/cuba/cienfuegos
    <http://www.mysite.com/cuba/cienfuegos> to
    www.mysite.com/app/city/index?country=cuba&city=cienfuegos
    <http://www.mysite.com/app/city/index?country=cuba&city=cienfuegos>
    www.mysite.com/cuba/cienfuegos/one_place
    <http://www.mysite.com/cuba/cienfuegos/one_place>
    to
    www.mysite.com/app/places/index?country=cuba&city=cienfuegos&place=one_place
    
<http://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:

|
defindex():
ifrequest.args(2):
returnplace(request.args)
elifrequest.args(1):
returncity(request.args)
else:
returncountry(request.args(0))

defcountry(country):
    response.view ='default/country.html'
...
returndict(...)

defcity(location):
|    response.view ='default/city.html'
|    country,city =location
...
returndict(...)

defplace(location):
    response.view = 'default/place.html'
    country,city,place =location
...
returndict(...)
|

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 web2py+unsubscr...@googlegroups.com <mailto:web2py+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.



--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

--
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to