[eluser]Madmartigan1[/eluser]
Hello Everyone!
Not 100% sure if this is a CI-specific or MVC question:
Of course there are a million ways to do the same thing in php, but I'm wondering where these things truly belong in a CRUD app. This is not my first day on the job, so please just humor me :-P
Model or Controller?
Form validation/processing
Redirection
Setting status messages/flashdata
I've been doing all of this lately with one magic form processing controller that invokes a model->method by parameters passed to it. Something like this:
Code:
function do_action($model,$action,$id=false)
{
//crud methods from models would return true/false
$this->$model->$action($id)===true ? $status='success' : $status='error';
//this would load a language line like 'blogs_edit_success'
$this->session->set_flashdata($status,$this->lang->line($model.'_'.$action.'_'.$status));
redirect('some_page');
}
Forms would post to something like 'blog_model/edit_blog/13'
This keeps my app super-tidy, but I feel like it's a bad practice.
However, it seems like a huge waste of time to create a controller function for every form, and bad separation of logic to put validation methods in the controller.
The CI docs even suggest that the form post to
itself, which does reduce the need for extra functions, but it seems like validation makes more sense to be in the model.
Sorry, I'm babbling. Once more:
Model or Controller?
Form validation/processing
Redirection
Setting status messages/flashdata
ALSO: Is it better practice to post to a url with the "id" in it, or use a hidden input?
Any comments or suggestions?