Just a clarification, the method I described is not intended to only
"allow" the different environment variables within your app, but extend
them by creating a "wrapper" in which you can create your "common" or
"helper" methods available throughout your application.
Agreed that If what you need is only access to environment variables,
indeed current is the way yo go.
Thx,
Julio
On 02/16/2014 04:40 PM, Anthony wrote:
Note, instead of this method, you can now use gluon.current.
Anthony
On Sunday, February 16, 2014 6:32:13 PM UTC-5, Julio F. Schwarzbeck wrote:
I assume that if you will use modules they'll probably be
implemented in
some kind of class, I'd personally do something similar to this..
# mymodule.py
class ModuleHelper(object):
""" Sample Helper for common methods.
"""
def __init__(self, environment):
self.request = environment['request']
self.response = environment['response']
self.session = environment['session']
self.cache = environment['cache']
self.db = environment['db']
self.auth = environment['auth']
def method(self):
self.request.get('variable', ....)
...
And when instantiating the module say from a model:
# mymodel.py
from mymodule import ModuleHelper
...
And Later in the same mymodel.py
...
# Make the module class/methods available:
my_module_helper = ModuleHelper(globals())
Now you can use my_module_helper.my_method(params) from within any view
or controller..
Hope it helps.
Julio
On 02/16/2014 01:55 PM, Stef Mientki wrote:
> hello,
>
> how to get globals like "request" available in my own modules ?
>
> thanks,
> Stef
>
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/ez6zc...@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
--
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/groups/opt_out.