Делаю как описано в доке.
config.php
Код: Выделить всё
'components' => [
'settings' => [
'class' => 'common\models\Settings',
],
'view' => [
'class' => 'yii\web\View',
'renderers' => [
'twig' => [
'class' => 'yii\twig\ViewRenderer',
'cachePath' => '@runtime/Twig/cache',
// Array of twig options:
'options' => [
'auto_reload' => true,
],
'globals' => [
'html' => ['class' => '\yii\helpers\Html'],
'Settings' => ['class' => '\common\models\Settings']
],
'uses' => ['yii\bootstrap'],
'functions' => [
'csrfToken' => 'common\helpers\FormHelper::csrfToken'
]
],
// ...
],
],
Код: Выделить всё
{{ Settings.someFoo() }}
Код: Выделить всё
namespace common\models;
class Settings {
public function someFoo(){
return 'some text';
}
Пробовал играться по всякому, менять тип метода, регистр, слешы добавлял убирал, добавлял common\models в uses - не получается
Что я не так делаю?
Причем мне было бы удобно так же через app обратиться, но почему то к примеру {{ app.user.isGuest }} "пингуется", а вот мой расширенный класс {{ app.settings.vk_link }} - нет
Код: Выделить всё
class Settings {
public function __get($property){
$config = \Yii::$app->db->createCommand('
select * from config limit 1
')->queryOne();
return isset($config[$property]) ? $config[$property] : null;
}