global controller?

9 views
Skip to first unread message

g-man

unread,
Apr 7, 2009, 3:44:44 PM4/7/09
to web2py Web Framework
I am learning all the new auth, crud, and mail tools now, and I have
one question:

Does web2py use the 'default' controller as an implicit global
controller across a single application, or is that even possible?

Here is my situation. When I create my:

## default.py controller
def user():
return dict(form = auth())

Then I expose:

## request
application/default/user/login

Which is not as clean in terms of MVC, because I in effect have an
additional (virtual) controller (named 'user') created, which then
calls the function 'login'.

Ideally, I would like:

## request
application/user/login

...to expose the function, which would require treating 'default' as a
global controller, as it were. I tried creating a 'login' controller,
but the request still required an extra term in the request (app/login/
user/login) - not pretty.

I hate to say Rails does something like this with the 'application'
controller, because any code in that file is global to the app.

I guess what I am looking for is web2py to look in the 'default'
controller first if any parsed controller/function candidate can not
be found, and only then raise the error on failure.

That way we can have a simpler request syntax (more RESTful), and the
result would be a good fit in the case of auth, crud, and mail,
because these are usually site-wide administrative functions anyway.

Programming is fun again, thanks to web2py!

waTR

unread,
Apr 7, 2009, 4:04:04 PM4/7/09
to web2py Web Framework
You can do what you are talking about via routes.py.

I believe this will do it:
routes_in=(
('/yourapp/default/$f.html','/yourapp/$f'),
)

mdipierro

unread,
Apr 7, 2009, 4:58:05 PM4/7/09
to web2py Web Framework
You can do:


index_url=URL(r=request,f=index')

def login(): return dict(form = auth.login(next=index_url))
def register(): return dict(form = auth.register(next=index_url))
...
etc.

Massimo
Reply all
Reply to author
Forward
0 new messages