php - Yii2 的嵌套集为 foreach() 提供的参数无效

标签 php yii2 nested-sets

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

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

一切严格按照说明书进行!

创建所有模型时出现错误:

enter image description here

enter image description here

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

类别模型:

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

最佳答案

CategoryQuery 类中需要ActiveQuery 而不是ActiveRecord

关于php - Yii2 的嵌套集为 foreach() 提供的参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33050657/

相关文章:

mysql - 搜索嵌套集

php - 将 MySQL 嵌套集连接到另一个表

php - 我收到此错误,有人可以帮忙吗? "Column count doesn' t 第 1 行的匹配值计数"

php - Yii2 显示记录标签

php - ZF2 - 子查询

php - yii2: 在打印中水平对齐 div?

php - Yii2 创建两个注册表单?

mysql - 获取MySQL中给定类别的子类别下的项目数

php - mysqli_real_escape_string 似乎不起作用

php - APNS 与 Google App Engine 和 PHP SSL 错误