Welcome Guest, Not a member yet? Register   Sign In
What to put in controller and what to put in model?
#1

[eluser]mvdg27[/eluser]
Hi,

After reading some stuff about Models on this forum, I decided to start using them as well. Before I simply put everything in my controllers.

I get the idea of Models, but am running into some day-to-day decisions about what to put in the model, and what to put in the controller.

1) I have a funtion in the Model returning one database row. After I want to make sure, there is no html and no slashes in the data. So I run:

Code:
foreach($row as $key=>$value) {
  $data[$key] = stripslashes(strip_tags($value));
}

Should I do this in the model or the controller?

2) Before inserting data into the database I check it for validity. A very simple example:

Code:
if(!$this->input->post('name')) $errors['name'] = $this->lang->line('error_name');
// some more checks

if(!count($errors)) {
  // prepare database input
  $db_input['name'] = strip_tags($this->input->post('name'));
            
  // friendly url
  $db_input['friendly_url'] = url_title(strip_tags($this->input->post('name')));

  // insert/ update statement here with $db_input as variable
  return true;
}
else {
  return false
}

This is currently all in my controller, but I'm in doubt which part should stay in the controller and which part should go to the model.

Probably there are more of these kind of decisions. And off course I understand there is no single right way. But as I'm using Models for the first time, I'd appreciate some advice here. If one of you has experience with other kinds of issues of doubt, please let them know as well (and how you solved them). I'm sure either myself or someone else will run into the same issue as well, at one point Smile

Thanks! -Michiel


Messages In This Thread
What to put in controller and what to put in model? - by El Forum - 01-10-2009, 07:42 AM
What to put in controller and what to put in model? - by El Forum - 01-10-2009, 08:51 AM
What to put in controller and what to put in model? - by El Forum - 01-11-2009, 07:29 AM
What to put in controller and what to put in model? - by El Forum - 01-11-2009, 09:56 PM
What to put in controller and what to put in model? - by El Forum - 01-11-2009, 10:30 PM
What to put in controller and what to put in model? - by El Forum - 01-12-2009, 02:20 AM
What to put in controller and what to put in model? - by El Forum - 01-12-2009, 02:21 AM
What to put in controller and what to put in model? - by El Forum - 01-12-2009, 08:21 AM
What to put in controller and what to put in model? - by El Forum - 01-12-2009, 08:37 AM
What to put in controller and what to put in model? - by El Forum - 01-12-2009, 08:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB