使用方法
1.下載文件並解壓到protected/extensions
2.插入數據庫
CREATE TABLE IF NOT EXISTS `tree` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`lft` int(11) NOT NULL,
`rgt` int(11) NOT NULL,
`level` int(11) NOT NULL,
`parent_id` int(11) NOT NULL,
`name` varchar(256) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=38 ;
3.控制器加入actions
public function actions()
{
return array(
'treeMoveUp'=>'ext.tree.actions.TreeMoveUpAction',
'treeMoveDown'=>'ext.tree.actions.TreeMoveDownAction',
'treeCreate'=>'ext.tree.actions.TreeCreateAction',
'treeUpdate'=>'ext.tree.actions.TreeUpdateAction',
'treeLoad'=>'ext.tree.actions.TreeLoadAction',
'treeDelete'=>'ext.tree.actions.TreeDeleteAction',
'treeChildren'=>'ext.tree.actions.TreeChildrenAction',
'treeChildrenParent'=>'ext.tree.actions.TreeChildrenParentAction',
'treeCreateParent'=>'ext.tree.actions.TreeCreateParentAction',
);
}
4.加入管理頁面的方法
public function actionIndex()
{
$this->render('index');
}
5.加入路由驗證(必須加上,否則你的ajax無法通過)
public function accessRules()
{
return array(
array('allow',
'actions'=>array('index','treeChildrenParent','treeDelete','treeLoad',
'treeUpdate','treeCreate','treeMoveDown','treeMoveUp','treeChildren','treeCreateParent'),
'users'=>array('admin'),
),
array('deny',
'users'=>array('*'),
),
);
}
6.最後一步在view加入如下代碼即可,作用是調用此控件
<?php $this->widget('ext.tree.widgets.TreeWidget',array('modelName'=>'Tree'));?>