S
S
Sergey Zhukov2015-10-11 14:53:49
Yii
Sergey Zhukov, 2015-10-11 14:53:49

How to get rid of Invalid argument supplied for foreach error in yii2?

I welcome everyone.
I don’t know where to write anymore, no one knows ;(
The third day I’m struggling with the error:
I use this extension https://github.com/creocoder/yii2-nested-sets
There were no problems for Yii1. I
did everything strictly according to the manual, but it crashes error
49e5cb38f94e4a298299a47ad3e84f08.png
full screenshot size: https://yadi.sk/d/HtM4ECmRjewsY
Moreover, this error occurs on any access to the Categories table , if I remove the behavior, then the object comes in.
i.e. I do $roots = Categories::find()- >roots()->all() ;
Error.Categories
model

<?php

namespace backend\models;

use creocoder\nestedsets\NestedSetsBehavior;
use yii\db\ActiveRecord;

class Categories extends ActiveRecord
{

  public function behaviors() {
    return [
      'tree' => [
        'class' => NestedSetsBehavior::className(),
         'treeAttribute' => 'tree',
      ],
    ];
  }

  public function transactions()
  {
    return [
      self::SCENARIO_DEFAULT => self::OP_ALL,
    ];
  }

  public static function find()
  {
    return new CategoryQuery(get_called_class());
  }
}

CategoryQuery Model
<?php

namespace backend\models;

use creocoder\nestedsets\NestedSetsQueryBehavior;
use yii\db\ActiveRecord;

class CategoryQuery extends ActiveRecord
{
  public function behaviors() {
    return [
      NestedSetsQueryBehavior::className(),
    ];
  }
}

Table migrated from Yii1 (fields renamed for Yii2 nested-sets extension)
rgY0n3H3bEN.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Zhukov, 2015-10-11
@Adobe

ActiveQuery not ActiveRecord -_-

M
Maxim Timofeev, 2015-10-11
@webinar

Weird. I used it on yii2 everything worked. Show output

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question