我使用 https://github.com/creocoder/yii2-nested-sets Yii2 的扩展!
所以,Yii1 的第一个版本很好,但在这个版本中我遇到了一些问题。
一切严格按照说明书进行!
创建所有模型时出现错误:
此错误出现在对类别表的任何查询中。如果删除行为整个工作 ;(
类别模型:
<?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/