nestedsetbehavior

hi yii community,

i cant get the extension nestedsetbehavior to work.

What i want is to create a child node to a root node with calling category/create.

BUT when appendTo() method is called nothing happens.

I use yii v1.1.10 and this tutorial: http://www.yiiframework.com/extension/nestedsetbehavior/

model code




public function rules()

	{

		return array();

	}

    public function behaviors()

    {

      return array(

            'nestedSetBehavior'=>array(

                'class'=>'application.extensions.NestedSetBehavior.NestedSetBehavior',

                'leftAttribute'=>'lft',

                'rightAttribute'=>'rgt',

                'levelAttribute'=>'level',

                'hasManyRoots'=>false,

        ));

    }



controller code:




public function actionIndex()

	{

		$model = Category::model();

		

		$categories=$model->findAll('id<>'. 1);

		

		$this->render('index',array(

			'categories' => $categories,

		));

	}

public function actionCreate()

	{

		$model=new Category;

		

		if(isset($_POST['Category']))

		{

			echo $_POST['Category']['id'] . '<br />';

			echo $_POST['Category']['title'] . '<br />';

			

			$root = Category::model()->findByPk(1);

			

			$element=new Category;

			$element->title=$_POST['Category']['title'];

			$element->appendTo($root);

		}



index view code:




<?php

	

	$level=0;


	foreach($categories as $n=>$category)

	{

		if($category->level==$level)

			echo CHtml::closeTag('li')."\n";

		else if($category->level>$level)

			echo CHtml::openTag('ul')."\n";

		else

		{

			echo CHtml::closeTag('li')."\n";


			for($i=$level-$category->level;$i;$i--)

			{

				echo CHtml::closeTag('ul')."\n";

				echo CHtml::closeTag('li')."\n";

			}

		}


		echo CHtml::openTag('li');

		echo CHtml::encode($category->title);

		$level=$category->level;

	}


	for($i=$level;$i;$i--)

	{

		echo CHtml::closeTag('li')."\n";

		echo CHtml::closeTag('ul')."\n";

	}

	

	echo CHtml::link('Root Element erstellen', CHtml::normalizeUrl(array('create')));


?>



_form view code:




<?php

	

		$dataArr = array();

		$combo_populate = Category::model()->findAll();

		

		foreach($combo_populate as $comboVal)

		{

			array_push($dataArr, $comboVal['title']);

		}

		

		echo CHtml::label('Nach folgendem Element einfügen:','title');

		$this->widget('ext.combobox.EJuiComboBox', array(

			'model' => Category::model(),

			'attribute' => 'id',

			'data' => $dataArr,

			'options' => array(

				'onSelect' => '',

				'onChange' => 'alert("changed value : " + $(this).val());',

				'allowText' => true,

			),

		));

	?>


	<div class="row">

		<?php echo $form->labelEx($model,'title'); ?>

		<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>100)); ?>

		<?php echo $form->error($model,'title'); ?>

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

	</div>



Is someone out there who can help me with this?

thanks in advance :)

Edit: "appendTo" works now :confused: and if you want to delete a node: $element->deleteNode() …i dont know why the delete function isnt listed in tut?

the solution here:


http://www.yiiframework.com/forum/index.php/topic/38414-probando-nested-set-behavior/page__gopid__185028