On Saturday, April 9, 2011 6:40:03 PM UTC-4, 黄祥 wrote: > > actually my real intention is : > > i have the same function that repeated many times in 1 controller (repeated > to different tables), so that i would to make it simple just put it on > modules, what do you think about it? > > if i created the new function in 1 controller and then the other function > access it, i don't like because it can be access by the browser url, is > there any way to prevent it? (i mean i created 1 function, and the other > function access it, and can't be accessed via browser url) > As explained here (http://web2py.com/book/default/chapter/04#Dispatching), any function in a controller that either (a) takes any arguments or (b) starts with an underscore cannot be accessed via a URL. In your case, the 'manage' function takes arguments, so it cannot be accessed directly via URL (try it). If it didn't take any arguments and you still wanted to make it inaccessible, you could rename it to '_manage' (or simply give it a dummy argument that isn't used).
> > pardon, if i'm not wrong, i read that to put the function on the model is > not the best practice, what do you think about it? > I think it's OK to put a function in a model file if it is used across multiple controllers, particularly if the function needs access to the web2py global objects (that way, you don't have to worry about passing the globals to the function). If you have a few such helper functions, it would probably make sense to put them into a special helper model file (rather than sticking them all in your db.py file). At some point, it might make sense to start moving some functions out into modules and importing them when needed, but that's probably not necessary until your app starts to get a lot bigger and more complex. One thing to keep in mind -- model files are executed in alphabetical order, so don't put something in a model file if it needs to refer to something that's defined in another model file that comes later in alphabetical order. Anthony

