I have a very simple method that is meant to add validation rules from a form (if no ID, password is required otherwise not - New user vs update user).
public function edit($id = NULL){
$rules = $this->user_m->rules;
$id || $rules['password'] .= '|required';
$this->form_validation->set_rules($rules);
$this->load->view('_layout_admin_main',$this->data);
}
$rules is set in the model as (although I can't see how it's relevant):
public $rules = array(
'name' => array(
'field' => 'name',
'label' => 'Name',
'rules' => 'trim|required|xss_clean'
),
'email' => array(
'field' => 'email',
'label' => 'Email',
'rules' => 'trim|required|valid_email|callback__unique_email|xss_clean'
),
'password' => array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|matches[password_c]'
),
'password_c' => array(
'field' => 'password_c',
'label' => 'Password Confirmation',
'rules' => 'trim|matches[password]'
),
'username' => array(
'field' => 'username',
'label' => 'Username',
'rules' => 'trim|is_unique|xss_clean|required'
)
);
The error is Message: Array to string conversion ... Line Number: 27, the $id reference is causing it specifically when $id is NULL. When $id is set, it is fine and dandy. $id is definitely not an array.
I know this is vague but this literally is it. Please ask questions if you have any ideas and I'll post any more that you need.
$rules['password'] .= '|required';which is causing the problem. rules is an array where required is string. you are trying to concatanate string with array. im not sure thou but i also wants to know if someone solved for you i will also love to know what was the actual problem.