Welcome Guest, Not a member yet? Register   Sign In
What is business logic?
#1

[eluser]greedyh4mster[/eluser]
Hiya!

From my understanding about MVC, a better practice of it is to use the M in the pattern to contain the business logic and the interaction with database, also known as the 'Skinny Controller Fat Model'. Instead of leaving the business logic to the controller while the model handles only the database queries. One of the references I read regarding my point above is this link.

While reading, I have this question in mind. What exactly does it means by business logic?

For example:

In a model:
Code:
function hash_password($password){
   $this->password = md5($this->password.$salt);
   return $this->password;
}

Is hashing of password consider a business logic? In my assumption, I think it is. But if hashing of password is really considered a business logic. Then wouldnt generating the password salt be considered as a business logic as well?

For example:

In a model:
Code:
function generate_salt(){
   $this->load->helper('string');
   $this->salt = random_string('alnum', 10);
}

And above all those questions. While I am coding an application, I tends to use integer to determine the status/state of an object. Is this the 'best practice'? Or is there any better way?

For example:

I am writing a notification class. A user will be able to set a notification to either 'dismiss' or 'remind me later' which will in turn determines whether should a notification be displayed to a user in their account page or not.

So in the database, I would have an integer (0 or 1) field named 'status' to determine whether is it a 'dismiss' or 'remind me later'.

In the application level, I used the config file to 'give a name to these values'.

For example:

In the config file:
Code:
$config['notification_status_dismiss'] = 0;
$config['notification_status_remindmelater'] = 1;

So my question is. When I am determining the status of the notification (this means I will be using the item stated above in the config), are the above considered as business logic? Or are they simply just 'php logic'?

An example of considering it as a business logic:

In the controller:
Code:
function dismiss(){
   $this->notification_model->dismiss();
}

function remindmelater(){
   $this->notification_model->remindmelater();
}

In the model:
Code:
function dismiss(){
   $this->status = $this->config->item('notification_status_dismiss');
   $this->_set_status();
}

function remindmelater(){
   $this->status = $this->config->item('notification_status_remindmelater');
   $this->_set_status();
}

Another example:

In the controller (Trying to save a notification in the database):
Code:
function create($user_id, $action, $message){
   $this->notification_model->user_id = $user_id;
   $this->notification_model->action = $action;
   $this->notification_model->action = $message;
   $this->notification_model->save();
}

In the model:
Code:
function save(){
   $this->time = date("Y-m-d H:i:s", time());
   $this->db->insert('notifications', $this);
}

In the above example. The notification has a time field to keep track of the time when is the notification created on. If I based the theory on a controller is to 'redirect user's input to a model only', then the above example would be correct in that sense. Indirectly, it would also means that the 'time field' is considered as part of the business logic right?

Seriously need everyone to help me in pointing me to the correct direction of the MVC pattern. Like what is considered as a business logic? What is not?

Thank you guys for reading!


Messages In This Thread
What is business logic? - by El Forum - 04-29-2010, 10:11 AM
What is business logic? - by El Forum - 04-29-2010, 04:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB