Сan't call a static method of the model
nepster-web opened this issue · 5 comments
nepster-web commented
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
However if you use globals
for Profile class, everything works correctly.
bizley commented
So basically exactly what it says in the docs? ;)
nepster-web commented
@bizley, in the sense ?
I meant that the global
works, but the use
does not work.
the bug is relevant !!!
samdark commented
In most cases, except widgets and assets, you have to import classes via globals.
nepster-web commented
got it. thanks.