If it's just a few (small) functions, go ahead and put them in model files, 
as reading a few extra function definitions will probably have a negligible 
impact on performance. In particular, if the functions are used in many/most 
requests, you would save little by moving them to modules because you would 
end up importing them on most requests anyway. 
 
On Wednesday, April 13, 2011 8:11:00 PM UTC-4, 黄祥 wrote:

> hi, 
>
> i try to follow the advise about functions from : 
> http://web2py.com/book/default/chapter/11#Efficiency-and-Scalability 
>
> - Minimize the code in models: do not define functions there, define 
> functions in the controllers that need them or - even better - define 
> functions in modules, import them and use those functions as needed. 
> - Do not put many functions in the same controller but use many 
> controllers with few functions. 
>
> i have a functions (e.g, add data, select data, update data) that been 
> used in many controller, i got an adviced to put my functions on the 
> models instead of on modules to make it simple, but the book said do 
> not define functions in models. 
> my intention is not to repeat the same code in many controller 
> (inefficiency) and make my code simple 
>
> any suggestion or advice for this? 
>
> thank you so much. 
>
> steve van christie

Reply via email to