CodeIgniter Forums
Callable models in form_validation.php file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Callable models in form_validation.php file (/showthread.php?tid=77443)



Callable models in form_validation.php file - Omar Crespo - 09-02-2020

Hi I'm using CI 3.1.11 and, at the moment I can't use callable models in my config/form_validation.php file. Can you show me the code to do that, or this can't be done??

Thanks in advance


RE: Callable models in form_validation.php file - php_rocs - 09-02-2020

@Omar Crespo,

Is the form_validation.php file a custom file? Why didn't you create a library (https://codeigniter.com/userguide3/general/creating_libraries.html?highlight=custom%20helper) or helper (https://codeigniter.com/userguide3/general/helpers.html#extending-helpers) instead?


RE: Callable models in form_validation.php file - Omar Crespo - 09-05-2020

Yes, it is the custom file, located in config folder. I don't need as much as a new library. I'm asking because in the guide it said that anything is callable, but I found i can't call a model function directly, from my custom file.


RE: Callable models in form_validation.php file - php_rocs - 09-05-2020

@Omar Crespo,

Can you post your code? This will allow us to see it and make recommendations.


RE: Callable models in form_validation.php file - Omar Crespo - 09-05-2020

In application/config/form_validation.php

array (
'field' => 'password',
'label' => 'ContraseƱa',
//'rules' => array('trim','required','matches[passconf]',array('resol_127_2019',$this->user_m,'resolucion_127_2019'),

'rules' => 'trim|required|matches[passconf]|callback_res_127_2019',
),

As you can see, there's a commented line, which has the call to my user_m model, but that doesn't work, so I'm using a callback function in the controller.

In the guide, form_validation library, there's a section that says
Callable: Use anything as a rule. The very first example is a direct call to a model. But that doesn't work for me.


RE: Callable models in form_validation.php file - InsiteFX - 09-06-2020

Did you try to autoload the model in config/autoload.php ?


RE: Callable models in form_validation.php file - Omar Crespo - 09-06-2020

(09-06-2020, 03:10 AM)InsiteFX Wrote: Did you try to autoload the model in config/autoload.php ?
Yes I did.

(09-06-2020, 03:10 AM)InsiteFX Wrote: Did you try to autoload the model in config/autoload.php ?
Yes I did.