Call to undefined function

Hello, this is my first post here and i hope you can help me with an error that it’s making me crazy a week ago.

I have defined 2 functions inside file controller for calculating several periods time, but my frustration is when i test it in browser and yii debugger throws the following error:

exception ‘yii\base\ErrorException’ with message ‘Call to undefined function frontend\controllers\ValidarSolicitud()’

The code where ValidarSolicitud is called from is this:

$tipo = 'Solicitud de vacaciones';

$fechacomienzo = $model->fechacomienzo;

$fechafin = $model->fechafin; 

$comentarios = $model->comentarios; 

$res = ValidarSolicitud($fechacomienzo, $fechafin);

And function is declared so:

public function ValidarSolicitud($fechainicio, $fechafinal)

What am i missing? I’m not able to find the problem, if anyone could help me i appreciate it.

Thanks in advance.


Try something like:

$res = $classInstance->validarSolicitud($fechacomienzo, $fechafin);

// for example 

$res = $model->validarSolicitud($fechacomienzo, $fechafin);

// Or in your case when I understood your desciption correct

$res = $this->validarSolicitud($fechacomienzo, $fechafin);

Also I would suggest you to write logic like calculations inside the model,

not in the controller.

Best Regards

1 Like

That was really fast answer :o , thank you very much MetaCrawler, it worked really nice and in addition i follow your suggestion and i’ll do these operations in model.

1 Like

Fat models and skinny controllers FTW :)

I’m afraid that it must be in controller because depending from date calculations results actionIndex logic will follow separates ways.

By the way, i’m having problems to trace the script execution because i’m not able to debug php properly.

Due to this fact, i’m writing ‘echo’ commands and ‘var_dump()’ but i don’t see its output in browser.

Is it possible to show information with this commands from Controller?. I’m still debugging the code in controller until it works fine and migrate it to Model.

Thanks in advance.