yiisoft/yii2-twig

Сan't call a static method of the model

nepster-web opened this issue · 5 comments

Doc:
https://github.com/yiisoft/yii2-twig/blob/master/docs/guide/template-syntax.md#importing-other-classes

I have model with static method:

<?php
namespace common\modules\users\models;

class Profile extends \nepster\users\models\Profile
{
// ...
    public static function getUserTypeArray(): array
    {
        return [
            self::AGENCY => [
                'label' => 'Агентство',
            ],
            self::OWNER => [
                'label' => 'Собственник',
            ],
            self::MEDIATOR => [
                'label' => 'Посредник',
            ],
            self::WANT_RENT => [
                'label' => 'Хочу снять',
            ],
        ];
    }
//...
}

In twig:

{{ use('/common/modules/users/models/Profile') }}
{{ dump(Profile.getUserTypeArray()) }}

And result: null

Q A
Yii version 2.0.37
Yii Twig version 2.4.0
Twig version
PHP version 7.4.16
Operating system alpine

However if you use globals for Profile class, everything works correctly.

So basically exactly what it says in the docs? ;)

@bizley, in the sense ?

I meant that the global works, but the use does not work.

the bug is relevant !!!

In most cases, except widgets and assets, you have to import classes via globals.

got it. thanks.