Welcome Guest, Not a member yet? Register   Sign In
Saving sets of rules in config files - Model Function
#1

(This post was last modified: 09-23-2016, 04:07 PM by Snake.)

So hello everybody, i was wondering if you could save sets of rules in the config file, but having a custom function of a model 

Kinda like combining this :

https://www.codeigniter.com/userguide3/l...onfig-file

PHP Code:
$config = array(
 
       'signup' => array(
 
               array(
 
                       'field' => 'username',
 
                       'label' => 'Username',
 
                       'rules' => 'required'
 
               ),
 
               array(
 
                       'field' => 'password',
 
                       'label' => 'Password',
 
                       'rules' => 'required'
 
               ),
 
               array(
 
                       'field' => 'passconf',
 
                       'label' => 'Password Confirmation',
 
                       'rules' => 'required'
 
               ),
 
               array(
 
                       'field' => 'email',
 
                       'label' => 'Email',
 
                       'rules' => 'required'
 
               )
 
       )
); 


With this : 

https://www.codeigniter.com/userguide3/l...-as-a-rule

PHP Code:
$this->form_validation->set_rules(
 
       'username''Username',
 
       array(
 
               'required',
 
               array('username_callable', array($this->users_model'valid_username'))
 
       )
); 


I tried with callback , and it worked, but i wanted to use directly the model method.(I tried adding the code but it gives me a error as users_model doesnt exist, and i added the model in the autoload)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB