Php Yii扩展-嵌套SetBeHavior未保存

Php Yii扩展-嵌套SetBeHavior未保存,php,frameworks,yii,nested-sets,nested-set-model,Php,Frameworks,Yii,Nested Sets,Nested Set Model,我正在尝试使用扩展名“NestedSetBehvaior”保存节点: 但是它并没有在数据库中保存任何东西 我尝试使用扩展附带的模式(extensions/yiiext/behaviors/trees/schema.sql) 我还添加了未包含的“标题”列 然后,我用Gii生成了控制器、模型和CRUD,并将其添加到新创建的模型:Category.php public function behaviors() { return array( 'n

我正在尝试使用扩展名“NestedSetBehvaior”保存节点:

但是它并没有在数据库中保存任何东西

我尝试使用扩展附带的模式(extensions/yiiext/behaviors/trees/schema.sql)

我还添加了未包含的“标题”列

然后,我用Gii生成了控制器、模型和CRUD,并将其添加到新创建的模型:Category.php

    public function behaviors()
    {
        return array(
            'nestedSetBehavior'=>array(
                'class'=>'ext.yiiext.behaviors.model.trees.NestedSetBehavior',
                'leftAttribute'=>'lft',
                'rightAttribute'=>'rgt',
                'levelAttribute'=>'level',
            ),
        );
    }
我还将NestedSetBehavior.php放在protected/extensions/yiiext/behavies/model/trees中/

然后我将其添加到控制器索引中:

$root=new Category;
$root->title='Mobile Phones';
$root->saveNode();
可能出了什么问题


另外,对于为多个用户存储多棵树(3000+),您建议使用哪种方法?想象一棵树有无限的深度。

我自己设法找到了解决方案。 问题出在模型“类别”中。 我更改了验证规则,因此不需要“lft”、“rgt”和“level”,因为它们是由NestedSetBehavior自动添加的

更改前:

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('lft, rgt, level', 'required'),
        array('level', 'numerical', 'integerOnly'=>true),
        array('root, lft, rgt', 'length', 'max'=>10),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        array('id, root, lft, rgt, level', 'safe', 'on'=>'search'),
    );
}
变更后:

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        //array('lft, rgt, level', 'required'),
        array('level', 'numerical', 'integerOnly'=>true),
        array('root, lft, rgt', 'length', 'max'=>10),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        array('id, root, lft, rgt, level', 'safe', 'on'=>'search'),
    );
}

它现在运行得很好。

我自己设法找到了解决方案。 问题出在模型“类别”中。 我更改了验证规则,因此不需要“lft”、“rgt”和“level”,因为它们是由NestedSetBehavior自动添加的

更改前:

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('lft, rgt, level', 'required'),
        array('level', 'numerical', 'integerOnly'=>true),
        array('root, lft, rgt', 'length', 'max'=>10),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        array('id, root, lft, rgt, level', 'safe', 'on'=>'search'),
    );
}
变更后:

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        //array('lft, rgt, level', 'required'),
        array('level', 'numerical', 'integerOnly'=>true),
        array('root, lft, rgt', 'length', 'max'=>10),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        array('id, root, lft, rgt, level', 'safe', 'on'=>'search'),
    );
}
它现在工作得很好