【问题标题】:Nested sets for Yii2 Invalid argument supplied for foreach()Yii2 的嵌套集 foreach() 提供的参数无效
【发布时间】:2015-10-10 05:29:00
【问题描述】:

我为 Yii2 使用https://github.com/creocoder/yii2-nested-sets 扩展!

所以,Yii1 的第一个版本很好,但在这个版本中我遇到了一些问题。

一切都严格按照说明书去做!

创建所有模型时我都会出错:

此错误出现在对 Category 表的任何查询中。如果删除行为整个工作;(

类别模型

<?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());
  }
}

类别查询模型

<?php

namespace backend\models;

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

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

【问题讨论】:

标签: php yii2 nested-sets


【解决方案1】:

ActiveQuery 代替 ActiveRecord 类 CategoryQuery 需要

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    • 2011-02-07
    相关资源
    最近更新 更多