A
A
Alexander Gorkin2018-07-18 15:37:26
Yii
Alexander Gorkin, 2018-07-18 15:37:26

Can't print array from table in Yii. Can't see Ccategory model. How to fix?

There was a problem. I'll attach the error to the picture. In the models folder, I created a Category class that describes the relationship between a category and a product. Next, I created a components folder in which I created the menuwidget class with which I want to print the entire array of the category table. Here is the code:

<?php 

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


class MenuWidget extends Widget {

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


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


  public function run() {
        $this->data = Category::find()->all();
    debug($this->data);
    return $this->tpl;
  }
}
?>

5b4f34838f5c0348697852.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vovella, 2018-07-24
@vovella

which template is basic or advanced? write explicitly - for example - frontend\models\Category

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question