Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Some_controller extends CI_Controller {
- public validate(){
- $rules = $this->some_model->get_custom_rules(array('rule1','rule2'));
- $this->form_validation->set_rules($rules);
- }
- }
- class Some_model extends CI_Model{
- public $validation_rules = array(
- array('field' => 'rule1', 'label' => 'label1', 'rules' => 'required|max_length[255]'),
- array('field' => 'rule2', 'label' => 'label2', 'rules' => 'required|max_length[255]'),
- );
- public function get_custom_rules(array $componets) {
- $rules = array();
- foreach ($this->validation_rules as $value) {
- if (in_array($value['field'], $componets)) {
- $rules[] = $value;
- }
- }
- return $rules;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement