Welcome Guest, Not a member yet? Register   Sign In
shared business logic is it a model or should i place in controller
#1

[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
#2

[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.
#3

[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.
#4

[eluser]Michael Wales[/eluser]
Good point Jolly - I forgot to address his other examples.
#5

[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




Theme © iAndrew 2016 - Forum software by © MyBB