Skip to main content

Posts

Showing posts from September, 2012

Using CTreeView with NestedSetBehavior in Yii

Getting this whole thing to work took me a few days of experimenting. Finally I've got it working. Posting it here hoping that it would save others some time and if I need it back in the future.

The Yii nested set behavior extension can be found at http://www.yiiframework.com/extension/nestedsetbehavior/.

Download the zip file and then extract it into the "app root"/protected/extensions/NestedSetBehavior folder. Make sure that the NestedSetBehavior.php can be found at "app root"/protected/extensions/NestedSetBehavior/NestedSetBehavior.php.

Then modify the model file which you want to use the behavior with. For example, I have a model Areas and the file "app root"/protected/models/Areas.php. Add to the mentioned file the following lines:
public function behaviors() { return array( 'nestedSetBehavior'=>array( 'class'=>'application.extensions.NestedSetBehavior.NestedSetBehavior', 'leftAttribute'=>&#…