Welcome Guest, Not a member yet? Register   Sign In
Design - Controller, Model, Helper, or Library
#1

[eluser]waterloomatt[/eluser]
Hi,

I am writing an app for teachers to post "subbing" positions. Respondents can reply and "bid" on positions. The school can choose a teacher based on various criteria.

One of our business rules is that school cannot "bid" on their owns posts. Another is that respondents can only bid on a particular position once. There are a few other rules that relate directly to the "bidding process".

What is the best/recommended approach to store these business rules? Everyone keeps saying that Models manipulate data, but in the same breath say that business rules are also contained in Models.

If so, would it look like this:
Controller:
Code:
insertBid()
{
    if (!$this->bidModel()->validateUserForBid($loggedInUserId))
    {
        // Set flashdata for errormessage and redirect.
        redirect("bid/$postId");
    }
}

Or should the controller, helper, or library handle the logic?

Cheers & thanks.
#2

[eluser]n0xie[/eluser]
I would probably do what you do now. Move the logic of validating if an user can or can't do a bid to a model. Then use the Controller to determine what should be done in either case. So if the validateUserForBid returns TRUE, do an insert. If it returns FALSE, redirect with an error message.

This way if you need to validate an user in different parts of your application, you can re-use the same model. If you ever change the business rules (maybe in the future someone can bid on his own position), you only need to change it in one place.




Theme © iAndrew 2016 - Forum software by © MyBB