Welcome Guest, Not a member yet? Register   Sign In
Callable models in form_validation.php file
#1

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
Reply
#2

(This post was last modified: 09-02-2020, 08:41 PM by php_rocs.)

@Omar Crespo,

Is the form_validation.php file a custom file? Why didn't you create a library (https://codeigniter.com/userguide3/gener...m%20helper) or helper (https://codeigniter.com/userguide3/gener...ng-helpers) instead?
Reply
#3

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.
Reply
#4

@Omar Crespo,

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

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.
Reply
#6

Did you try to autoload the model in config/autoload.php ?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(This post was last modified: 09-06-2020, 10:49 AM by Omar Crespo.)

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB