Hi, first sorry for the late reply, but I am on vacations and offline most 
of the time.

Here is an example on how we use the Yii2 framework router:

    'urlManager' => [
            'class' => \frontend\components\UrlManager::className(),
            'enablePrettyUrl' => true,
            'showScriptName' => false,
//            'suffix' => '.daxs',
            'rules' => [
                //contact
                ['pattern' => 'contact', 'route' => '/site/contact/', 
'defaults' => ['lang' => 'en-US']],
                ['pattern' => 'contactarme', 'route' => '/site/contact/', 
'defaults' => ['lang' => 'es']],
                //about
                ['pattern' => 'en/about', 'route' => '/blog/post/view/', 
'defaults' => ['lang' => 'en-US', 'postSlug' => 'about']],
                ['pattern' => 'es/acerca-de', 'route' => 
'/blog/post/view/', 'defaults' => ['lang' => 'es', 'postSlug' => 
'acerca-de']],
                //curriculum
                ['pattern' => 'en/curriculum', 'route' => 
'/blog/post/view/', 'defaults' => ['lang' => 'en-US', 'postSlug' => 
'curriculum-2']],
                ['pattern' => 'es/curriculum', 'route' => 
'/blog/post/view/', 'defaults' => ['lang' => 'es', 'postSlug' => 
'curriculum']],
                //feed
                ['pattern' => 'en/feed', 'route' => '/blog/post/feed', 
'defaults' => ['lang' => 'en-US'], 'suffix' => ".xml"],
                ['pattern' => 'es/canal', 'route' => '/blog/post/feed', 
'defaults' => ['lang' => 'es'], 'suffix' => ".xml"],
                //categories
                ['pattern' => 'en/<categorySlug>', 'route' => 
'/blog/post/category', 'defaults' => ['lang' => 'en-US']],
                ['pattern' => 'es/<categorySlug>', 'route' => 
'/blog/post/category', 'defaults' => ['lang' => 'es']],
                //articles
                ['pattern' => 'en/<categorySlug>/<postSlug>', 'route' => 
'/blog/post/view', 'defaults' => ['lang' => 'en-US']],
                ['pattern' => 'es/<categorySlug>/<postSlug>', 'route' => 
'/blog/post/view', 'defaults' => ['lang' => 'es']],
            ]
        ]

As you can see, there is no need of routes in and routes out, it 
automatically build in and out based on the rules, the 'defaults' key on 
each rule defines the variables, and the tags (<varName>) in the rules 
pattern are mapped as variables too, so calling:

http://myweb.com/contact will call controller site, function contact and 
pass variable lang with value en-US
and
url(c="site", f="contact", vars={lang:"en-US"}) will build 
http://myweb.com/contact

http://myweb.com/contactarme will call controller site, function contact 
and pass variable lang with value es
and
url(c="site", f="contact", vars={lang:"es"}) will build 
http://myweb.com/contactarme

http://myweb.com/en/curriculum will call controller post (of blog module), 
function view and pass variable lang with value en-US and variable postSlug 
with value curriculum-2
and
url(c="blog/post", f="view", vars={lang:"en-US", postSlug="curriculum-2"} 
will build http://myweb.com/en/curriculum

http://myweb.com/es/curriculum will call controller post (of blog module), 
function view and pass variable lang with value es and variable postSlug 
with value curriculum
and
url(c="blog/post", f="view", vars={lang:"es", postSlug="curriculum"} will 
build http://myweb.com/es/curriculum

http://myweb.com/my-category/my-post will call controller post (of blog 
module), function view and pass variable lang with value en-US and variable 
categorySlug with value my-category and variable postSlug with value my-post
and
url(c="blog/post", f="view", vars={lang:"es", postSlug="my-post", 
categorySlug="my-category"} will build http://myweb.com/my-category/my-post


In that way we can move the code to a new application, and use a complete 
different urls without change one single line of code.

Greetings.


El domingo, 31 de julio de 2016, 17:31:47 (UTC-4), Massimo Di Pierro 
escribió:
>
> Can you point to any other web framework that allows reverse mapping 
> path_info into query_string?
>
> I am not aware of other frameworks that allow this. I would like to see 
> what syntax they use. 
>
> Massimo
>
>
>
> On Sunday, 31 July 2016 09:53:28 UTC-5, Carlos Cesar Caballero wrote:
>>
>> Many thanks for your answer Massimo.
>>
>> I hope that you accept my next words as a constructive criticism.
>>
>> Because of "little things" like this, so many developers do not like 
>> web2py, the router should be completly independent from the app code, so 
>> any changes on the router will not affect the app code, right now I will 
>> need to build my app using a different framework.
>>
>> Of course I will continue using web2py, but will be great if I could use 
>> it without problems when my applications demands more exigent use cases. Of 
>> course, the most of the people do not think like me and begin to use 
>> another framework that works either with small and complicated 
>> applications, thats why they don't like and don't use web2py, not because 
>> they are "purists"
>>
>> Greetings.
>>
>> El domingo, 31 de julio de 2016, 2:39:17 (UTC-4), Massimo Di Pierro 
>> escribió:
>>>
>>> This is a limitation with routes out. The left hand side cannot contain 
>>> "?" and vars.
>>> You can maps path_info into request.vars in the way but not the vice 
>>> versa in the way out. You have to put the language in the args and the do 
>>> the remapping on the way out.
>>>
>>> On Friday, 29 July 2016 23:12:07 UTC-5, Carlos Cesar Caballero wrote:
>>>>
>>>> Hi everyone, again with problems with the router here, I have this rule 
>>>> in routes_in, and is working pefectly:
>>>>
>>>> ('/$lang/$country/$state/$city(?P<any>.*)', 
>>>> '/{app}/city/view\g<any>?lang=$lang&country=$country&state=$state&city=$city'.format(app=app))
>>>>
>>>> This maps the url and I can use the language, the country, the city and 
>>>> the state as variables in my controller, the problem is with the 
>>>> routes_out:
>>>>
>>>> ( 
>>>> '/{app}/city/view(?P<any>.*)?lang=$lang&country=$country&state=$state&city=$city'.format(app=app),
>>>>  
>>>> '/$lang/$country/$state/$city\g<any>')
>>>>
>>>> Always that I put something like ?lang=lang in routes_out it breaks, 
>>>> gives no error, but the rule don't work.
>>>>
>>>> I am having other problem, and is with the url vars position, web2py 
>>>> uses a dictionary in some step and don't keep the url vars order (even if 
>>>> I 
>>>> use a orderedDict in the URL() vars argument). I have used the Yii2 
>>>> framework router and it don't care about the url vars order. We have, or 
>>>> can we have something similar with web2py?
>>>>
>>>> Greetings.
>>>>
>>>>
>>>> El jueves, 7 de julio de 2016, 8:50:46 (UTC-4), Carlos Cesar Caballero 
>>>> escribió:
>>>>>
>>>>> Hi, I need some starting point to implement the URL based 
>>>>> internationalization using the pattern based router, I really need to use 
>>>>> the router, but there is so little documentation...
>>>>>
>>>>> I am clonning our yii2 cms base application (supporting right now 
>>>>> sites like http://santiagohermes.com http://anniaalonso.com, 
>>>>> http://alborarquitectos.com and http://casamabehostal.com) and it is 
>>>>> almost done (you can look working in http://daxslab.com/) but I need 
>>>>> to add some functionalities with the router before sharing it to everyone.
>>>>>
>>>>> Greetings.
>>>>>
>>>>

-- 
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