2013-06-28 5 views
1

내가 확장자가 "NestedSetBehvaior"로 노드를 저장하기 위해 노력하고있어 저장하지 .. http://www.yiiframework.com/extension/nestedsetbehavior/YII 확장 nestedsetbehavior

하지만 데이터베이스에 아무것도 저장되지

내가 스키마를 사용하여 시도하는 확장 기능 (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', 
      ), 
     ); 
    } 

나는 또한 보호/확장/yiiext/행동에 NestedSetBehavior.php 배치/모델/나무/

그리고 내가 컨트롤러 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'), 
    ); 
} 

그것은 지금은 완벽하게 작동합니다.