A
A
Abram Peters2019-01-10 07:40:17
Yii
Abram Peters, 2019-01-10 07:40:17

How to write a full path to functions in Yii2?

I prescribe a function and when I want to apply it by prescribing its path like this \\app\controllers\debug(Yii::$app);
I get an error: Call to undefined function app\controllers\debug()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lander, 2019-01-10
@nigma1996

If you haven't rewritten the autoload algorithm, then you can't call the function this way. So you can only call a class method. And the call should then be something like:

$controller = new \\app\controllers\DebugController();
$controller->debug(Yii::$app);

In your particular case, it would be more correct to write a helper
namespace app\helpers;

class SystemHelper
{
    public static function debug($app)
    {
        //Код функции
    }
}

And then call it
\app\helpers\SystemHelper::debug(Yii::$app);

A
Andrey, 2019-01-10
@VladimirAndreev

use function app\controllers\debug;
along with other use write..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question