2013-06-28 16 views
1

我試圖保存節點擴展名爲「NestedSetBehvaior」:http://www.yiiframework.com/extension/nestedsetbehavior/Yii的擴展 - nestedsetbehavior不節能

但它不保存在數據庫中的任何東西..

我嘗試使用模式,它附帶擴展名(extensions/yiiext/behaviors/trees/schema.sql)。

我還添加了「標題」列,但未包括在內。

然後我生成的控制器,型號& CRUD與GII和將此添加到新創建的模型:Category.php

public function behaviors() 
    { 
     return array(
      'nestedSetBehavior'=>array(
       'class'=>'ext.yiiext.behaviors.model.trees.NestedSetBehavior', 
       'leftAttribute'=>'lft', 
       'rightAttribute'=>'rgt', 
       'levelAttribute'=>'level', 
      ), 
     ); 
    } 

我也被放置在NestedSetBehavior.php在保護/擴展/ yiiext /行爲/模型/株/

然後我加入這個控制器的indexAction:

$root=new Category; 
$root->title='Mobile Phones'; 
$root->saveNode(); 

怎麼可能是錯的?

此外,你會推薦哪種方法爲多個用戶(3000+)存儲多棵樹?想象一棵無限深度的樹..

回答

1

我已經設法找到我自己的解決方案。 問題出在模型'Category'中。 我更改了驗證規則,因此'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'), 
    ); 
} 

它現在可以正常使用。