после установки многоязичности widget не показывает тексты

Общие вопросы по использованию второй версии фреймворка. Если не знаете как что-то сделать и это про Yii 2, вам сюда.
Ответить
Oqilxon1991
Сообщения: 3
Зарегистрирован: 2017.12.09, 11:35
Откуда: Ташкент
Контактная информация:

после установки многоязичности widget не показывает тексты

Сообщение Oqilxon1991 »

Здравствуйте я новинки в веб разработке нужен помощь от профессионалов. Я установил многоязичность в сайт всё работает хорошо но меню сайта находится виджете вот он пустой категории не показывают ни знаю как исправит это кто знает ошибку помогите
в MenuWidget:

Код: Выделить всё

<?php

namespace app\components;
use yii\base\Widget;
use app\models\Category;
use Yii;

class MenuWidget extends Widget{

    public $tpl;
    public $model;
    public $data;
    public $tree;
    public $menuHtml;

    public function init(){
        parent::init();
        if( $this->tpl === null){
            $this->tpl = 'menu';
        }
        $this->tpl .= '.php';
    }

    public function run(){
        // get cache
        if ($this->tpl == 'menu.php'){
            $menu = Yii::$app->cache->get('menu');
            if($menu) return $menu;
        }

        $this->data = Category::find()->indexBy('id')->asArray()->all();
        $this->tree = $this->getTree();
        $this->menuHtml = $this->getMenuHtml($this->tree);
        // set cache
        if ($this->tpl == 'menu.php'){
            Yii::$app->cache->set('menu', $this->menuHtml, 20);
        }
        return $this->menuHtml;
    }

    protected function getTree(){
        $tree = [];
        foreach ($this->data as $id=>&$node) {
            if (!$node['parent_id'])
                $tree[$id] = &$node;
            else
                $this->data[$node['parent_id']]['childs'][$node['id']] = &$node;
        }
        return $tree;
    }

    protected function getMenuHtml($tree, $tab = ''){
        $str = '';
        foreach ($tree as $category){
            $str .= $this->catToTemplate($category, $tab);
        }
        return $str;
    }

    protected function catToTemplate($category, $tab){
        ob_start();
        include __DIR__ . '/menu_tpl/' . $this->tpl;
        return ob_get_clean();
    }


}


в menu.php

Код: Выделить всё

<li class="dropdown">
    <a href="<?= \yii\helpers\Url::to(['category/view', 'id' => $category['id']])?>">
        <img src="/images/<?= $category['icon']?>" alt="menu-icon1"><?= $category['name']?>
        <?php if( isset($category['childs']) ): ?>
        <i class="fa fa-angle-right" aria-hidden="true"></i>
        <?php endif;?>
    </a>
    <?php if( isset($category['childs']) ): ?>
    <ul class="dropdown-menu right">
        <li>
            <?= $this->getMenuHtml($category['childs'])?>
        </li>
    </ul>
    <?php endif;?>
</li>
Ответить