Is it possible to send a variable from the controller to a config file, in Codeigniter?

0

I am working with Codeigniter 3, I have a config file (form_validation.php) in which I have all my validation rules.

Within my configuration file (form_validation.php) I have a method that needs to receive a variable (in this case the user_id) here the code -

$config = array(
        'edit_user' => array(
          array(
                     'field' => 'edituser_email',
                     'label' => 'Email',
                     'rules' => "required|trim|xss_clean|valid_email|edit_unique[users.email.$user_id]",
                     'errors' => array(
                        'required' => 'Campo obligatorio.',
                        'valid_email' => 'Formato de correo no válido.',
                        'edit_unique' => 'Ya existe un usuario con este correo.'
                     )
          )
        )
);

But I can not send the variable ($ user_id) from my controller -

$data['user_id'] = $id;
if ($this->form_validation->run('edit_user',$data) === FALSE)

I get an error: Message: Undefined variable: user_id

Some of you have tried to do this, I know that from the method in my Controller, I can add all my rules; but I want to keep these rules separate, using a config file.

Thank you very much for your attention.

    
asked by aguileraq 09.05.2017 в 08:01
source

1 answer

0

You are sending an array. You must receive it as such. That's why it tells you the variable that does not recognize user_id . If you notice, when this type of errors appear, it is because the function has not referred to the variable user_id, maybe with a var_dump you can read or you can try sending

if ($this->form_validation->run('edit_user',$data['user_id']) === FALSE) and see what throws you.

    
answered by 01.04.2018 в 21:40