Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You are referencing the entire "password" array. To add to the "rules" string it should be like this:

$rules['password']['rules'] .=  '|required'
share|improve this answer
    
oh thank you, didn't understand how i didn't see that though. –  user1621727 Aug 4 '13 at 2:11
    
Yeah it's pretty basic. –  Wesley Murch Aug 4 '13 at 2:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.