• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation+Filtering

#11
[eluser]Colin Williams[/eluser]
I touched on this in my recent screencast, where I say I go back and forth about where the form should be defined. The ultimate goal is to have it defined in only one place. My argument for the Controller is one of ergonomics (if that makes sense) because I like to be able to tweak the entire form submission, validation, response without having to bounce between the Controller and the model. This is the same reason I don't like putting validation rules and fields in config files.

There are good arguments to be made for the model, of course, but having it in the controller just works for me (this coming from doing it all ways mentioned before)

#12
[eluser]RESPECT[/eluser]
try to follow what colin said, keep things divided up as it was 'intended' to be with the term MVC (model, view, controller).
I know what I'm about to say now goes against my previous thoughts (please dont colin Tongue) but it would be better to have those validation rules tied into your controller as it allows your application to be more agile, rather then having the rules set in the model. If you have base validation rules and functions, just setup another controller, then make all of your other controllers extend it.

ex.

Random controller(magic happens with the extend partSmile)
Code:
<?php
class Portfolio extends Validation_Controller {
#code...
}
?>

Validation Controller
Code:
<?php
class Validation_Controller extends Controller {

function Validation_Controller {
parent::Controller();
var $validation_rules['standard'] = array (
  'name' => 'required' // etc. etc.
);

var $validation_rules['extreme'] = array (
  'name' => 'required' // etc. etc.
);
}

function _set_validation_rules($rules = 'standard')
{
  if (is_array($rules)) {
    $this->validation->set_rules($rules) // allow the use of custom rules
  } else {
    $this->validation->set_rules($this->validation_rules[$rules]);
  }
  
}

}
?>

Your way is good but try not to put that sorta stuff in the model...though error checking like this:
Code:
function view_all_from($table) {
    $query = $this->db->get($table);
    $exe = !$query ? false : $query->result();

    return $exe;
    }
imho is goodSmile


Hope this helps,

Respect

#13
[eluser]Colin Williams[/eluser]
Quote:I know what I’m about to say now goes against my previous thoughts (please dont colin)

Haha.. no big deal. I change my mind all the time about this stuff.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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