yiisoft / yii2-twig

Yii 2 Twig extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
136 stars 61 forks source link

Сan't call a static method of the model #130

Closed nepster-web closed 3 years ago

nepster-web commented 3 years ago

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
nepster-web commented 3 years ago

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

bizley commented 3 years ago

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

nepster-web commented 3 years ago

@bizley, in the sense ?

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

the bug is relevant !!!

samdark commented 3 years ago

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

nepster-web commented 3 years ago

got it. thanks.