• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controller / model separation, templating

#1
[eluser]batfastad[/eluser]
Hi everyone

Just getting started with CI and currently converting a simple project to MVC. I have a few questions on what the best practice is with models and controllers.

1) Validation of form data, should I do this in the controller or in the model? My guess is controller, as depending on the result of the validation I might not even need to run DB queries, e.g.: if required data is missing.

2) If I have a controller function that needs multiple but separate DB queries, should I set each query up as a seperate function in my model?
In this case the queries are separate, they will only ever be run one after the other, never individually.
Or should I combine the queries into a single function in my model?

3) I'm defining a constructor in each model...
Code:
public function __construct() {
$this->load->database();
}
Even if I'm calling multiple model functions from the same controller function, then there's still only one instantiation of the class so there should only be a single DB connection. Is that right?

4) But to be on the safe side should I just set the database to auto-load in my config?
I don't really want multiple DB connections going off when they're not really needed.

5) I'm setting up my forms manually at the moment, not using the helpers yet.
I have a form that sends data via a jQuery AJAX POST and the result that's sent back is a line of HTML, either success or error. Should I still have that coming out of a view or should I echo that out directly from the model or controller?
It seems a bit pointless setting up a view just to display a simple success/error message.

Sorry if all these are obvious questions. I just wanted to get some definitive opinions before carrying on.

Cheers, B


Messages In This Thread
Controller / model separation, templating - by El Forum - 09-21-2012, 11:00 AM
Controller / model separation, templating - by El Forum - 09-21-2012, 11:03 AM
Controller / model separation, templating - by El Forum - 09-21-2012, 03:47 PM
Controller / model separation, templating - by El Forum - 09-21-2012, 11:53 PM
Controller / model separation, templating - by El Forum - 09-22-2012, 12:41 AM
Controller / model separation, templating - by El Forum - 09-22-2012, 05:23 PM
Controller / model separation, templating - by El Forum - 09-23-2012, 11:31 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.