Call a Function from view

Hello, i have a php file(MyHelpers) located in components folder,
inside of this i have the function findComandos()

i just need to call the function from a view

thanks for the help :star_struck:

What exatly is the problem?

If MyHelpers is a simple class and not a registered component in main/config.php, inside your view:

$myHelpers = new \yii\components\MyHelpers();
$myHelpers->findCommandos($con);

Take care to change namespace, because \yii\components namespace suggests something related to Yii official components.

sry i will to try to explain me better

example:

i have my function findVar(var) located in SiteController.

i need to call that function from several views for example user/index

thank you for your help and for your patience

hello fabrizio thanks for your help

example:

i have my function findVar(var) located in SiteController.

i need to call that function from several views for example user/index

thank you for your help and for your patience

this is layouts\left

here i need to call several times the function findvar($var)

actually i am copying the public function in every controller, for example

in usuarios controller
in dependencias controller etc in every controller

i want to call the function severall times but only from SiteCotroller

thanks for your time

Calling \backend\controllers\SiteController::findVar() should do what you want.

You may want to create a helper class and put that method in it since it has nothing to do with your controllers logic.