1

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.

1
  • i think it is $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. Commented Oct 25, 2014 at 23:56

1 Answer 1

2

I think there is a small issue with the way you concatenate required to the rules, try this instead :

public function edit($id = NULL){
  $rules = $this->user_m->rules;
  $id || $rules['password']['rules'] .= '|required'; // issue was here
  $this->form_validation->set_rules($rules);
  $this->load->view('_layout_admin_main',$this->data);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Can't believe it was something that obvious. thanks @MaxiWheat!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.