I am using Codeigniter to develop an application, and have been reading bits about Ruby on the Rails. In particular Skinny Controller, Fat Model seemed to make perfect sense. It really allows me to look at the controller and know what the hell is actually going on, and allows very very quick adjustments and bug fixes.
However the one stumbling block I have is, where do I handle POST data. Do I call it into a bunch of variables in the Controller and pass that to the model. Or do I just access it direct from the model?
Additionally I am having the same problem when thinking about prepopulating form field values. Should I call a single method from the controller and pass the result to the view or just make a bunch of variables and pass them to the view directly from the controller.
Any guidance greatly appreciated.
There are a couple ways to handle this, but generally, it is not considered consistent for the view to call
$this->CI->input->post( $item ). Generally, your view is best if restricted to purely displaying data and the only function calls it should make are calls likeanchor,lang, et al. It is also better to avoid having your models grab data from outside, especially when they can be passed in the information (possible exceptions are language and config data). The traditional separation of concerns in CodeIgniter is that the Model stores data, the View displays data, and the Controller manipulates it (sometimes this will be libraries manipulate the data and the Controller calls library functions).Pre-populating is clearer if the information is passed in to the view and then output from the view as
<?php echo $value; ?>, but there are some exceptions.Basically, these are the rules I follow: