создал мультиязычное меню, но при обращении к нему выводить такую ошибку Call to a member function getDataMenu() on array. Где я ошибся? Вот код виджета
<?php
namespace frontend\components;
use Yii;
use yii\base\Widget;
use frontend\models\Menu;
use frontend\models\LangMenu;
class MenuWidget extends Widget
{
public $tpl;
public $model;
public $data;
public $nav;
public $menuHtml;
public $pages;
public function int() {
parent::init();
if($this->tpl === null) {
$this->tpl = 'menu';
}
$this->tpl .= '.php';
}
public function run() {
$this->tpl .= '.php';
$this->pages = new Menu;
$this->data = $this->pages->getMenus();
$this->nav = $this->getTree();
$this->menuHtml = $this->getMenuHtml($this->nav);
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($navs, $tab = '') {
$str = '';
foreach ($navs as $nav) {
$str .= $this->catToTemplate($nav, $tab);
}
return $str;
}
protected function catToTemplate($nav, $tab) {
ob_start();
include __DIR__.'/menu_tpl/'.$this->tpl;
return ob_get_clean();
}
}
А это модел Menu
<?php
namespace frontend\models;
use Yii;
use \yii\db\ActiveRecord;
class Menu extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'menu';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['alias'], 'required'],
[['alias'], 'string', 'max' => 255],
[['alias'], 'unique'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'alias' => Yii::t('app', 'Alias'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getLangMenu()
{
return $this->hasMany(LangMenu::className(), ['menu_id' => 'id']);
}
/*
* Возвращает массив объектов модели menu
*/
public function getMenus(){
return $this->find()->indexBy('id')->asArray()->all();
}
/*
* Возвращает данные для указанного языка
*/
public function getDataMenu(){
$language = Yii::$app->language;
$data_lang = $this->getLangMenu()->asArray()->where(['lang'=>$language])->one();
return $data_lang;
}
public function getMenu($alias){
return $this->find()->where(['alias' => $alias])->one();
}
}
Сборка персонального компьютера от Artline: умный выбор для современных пользователей