Nested sets for Yii2 Invalid argument supplied for foreach()
Asked Answered
G

1

6

I using https://github.com/creocoder/yii2-nested-sets extension for Yii2!

So, first version for Yii1 was good but in this version i have some problem.

All done strictly according to the manual!

When created all models i earn error:

enter image description here

enter image description here

This error appear at any query to Category table. If delete behavior entire work ;(

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(),
    ];
  }
}
Gaillard answered 10/10, 2015 at 5:29 Comment(6)
show your category model and controllerGranger
cs628016.vk.me/v628016930/1ea86/jRzxP35vIkY.jpgGaillard
cs628016.vk.me/v628016930/1ea8d/1eXLUyfYqds.jpgGaillard
its better to edit your question than posting imagesNakada
We cannot identify errors in image. it's unreadable.Traci
Replace images on code snippetsGaillard
G
0

ActiveQuery instead ActiveRecord in class CategoryQuery need

Gaillard answered 14/10, 2015 at 5:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.