shared business logic is it a model or should i place in controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: shared business logic is it a model or should i place in controller (/showthread.php?tid=2839) |
shared business logic is it a model or should i place in controller - El Forum - 08-27-2007 [eluser]Unknown[/eluser] I have an application that has models for clients data invoices products etc and the views etc However there is also the business logic like get the client see if his invoice is overdue etc and do what it needs to do I know I can do that in the controller however if I do that in one controller and if I have to do that again in another controller I would have to repeat that code so my question is should I have a model for those business rules or maybe a library The same for say a payment gateway logic would I be best making that into a model as that may be called by more than one controller thanks shared business logic is it a model or should i place in controller - El Forum - 08-27-2007 [eluser]Michael Wales[/eluser] I would definitely take something like that and make it a method within my invoices model. The basic rule of thumb is: recurring function called from controller = model recurring function called from view = helper In your case, something like passing the invoice ID to an is_overdue() function within the model that returns TRUE/FALSE would work perfectly. shared business logic is it a model or should i place in controller - El Forum - 08-27-2007 [eluser]Rick Jolly[/eluser] [quote author="walesmd" date="1188266974"] The basic rule of thumb is: recurring function called from controller = model recurring function called from view = helper [/quote] My take: function called from view = helper function/method called from controller = helper, library, or model A model is for getting/setting data, whether from a database, file, feed, etc - a fairly ignorant entity. A library class has methods that share and work with its variables. I think a library would normally have more functionality than a model - it could even use models. Maybe a library might make more sense in this case - especially for the payment gateway. shared business logic is it a model or should i place in controller - El Forum - 08-27-2007 [eluser]Michael Wales[/eluser] Good point Jolly - I forgot to address his other examples. shared business logic is it a model or should i place in controller - El Forum - 08-28-2007 [eluser]Unknown[/eluser] thanks I was thinking along those lines and now I have all the database tables done the work begins god I hate forms |