On Nov 13, 2011, at 3:38 PM, Bruno Rocha wrote:

> I am going to test the trick in models. it is useful to create /username 
> services.
> 
> 

The reason this works (if it works) is that the existing dispatch code runs the 
models before it looks at request.controller to choose the controller. So 
editing it should work, as a very general way of rewriting.

Of course, this has implications for controller-specific models, so you'd need 
to be cautious about that.

Another thing to be cautious about is that since this is undocumented behavior, 
it might change in the future. This kind of programmatic rewrite can be quite 
useful, but doing in in the model isn't ideal. Perhaps a pre-model hook as part 
of rewrite?
> http://zerp.ly/rochacbruno
> 
> Em 13/11/2011 17:21, "Jonathan Lundell" <[email protected]> escreveu:
> On Nov 13, 2011, at 11:07 AM, Bruno Rocha wrote:
> 
>> > Here's an alternative, though. I think it might work. In your controller, 
>> > do something like this:
>> >
>> > def articles():
>> >    whatever
>> >
>> > artigos = articles
>> > articulos = articles
>> > artiklid = articles
>> >
>> 
>> it does not works. to work need to be
>> 
>> def artigos():
>>     return aricles()
>> 
>> and repeat for others...
>> 
>> the only problem is that I cant rename the controller name in this way.
> 
> Oh, right, web2py looks at the text of a controller and not at its symbols.
> 
> For controllers, you could link the alternate names (assuming this is 
> Unix-ish):
> 
> $ ln articles artigos
> $ ln articles articulos
> ...
> 
> 
> Yet another trick (undocumented and subject to change): in db.py (or anywhere 
> in your model files) translate request.controller and request.function.


Reply via email to