I have an edit class where i use for editing and adding new users. If the call has an id, means that it must call edit function, if it doesn't have an id, than it calls add function.
The problem that i'm facing is, if it's an edit class calling, i don't need the password field as required, but if add class is calling, i need to add required to password field. But when i try to add that, it gives me array to string conversation error.
Here is what i've done :
Model :
public $rules_admin = array(
'password' => array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|matches[password_confirm]'
),
'password_confirm' => array(
'field' => 'password_confirm',
'label' => 'Password_Confirm',
'rules' => 'trim|matches[password]'
)
);
Controller :
$id == NULL || $this->data['user'] = $this->user_m->get($id);
$rules = $this->user_m->rules_admin;
$id || $rules['password'] .= '| required'; // error is here
$this->form_validation->set_rules($rules);
// some stuff here