simpletree not working for me too … for me it is showing a revolving image with Loading.
I have ajaxcontroller
<?php
class AjaxController extends Controller
{
public function actionIndex()
{
$this->render('index');
}
// Uncomment the following methods and override them if needed
/*
public function filters()
{
// return the filter configuration for this controller, e.g.:
return array(
'inlineFilterName',
array(
'class'=>'path.to.FilterClass',
'propertyName'=>'propertyValue',
),
);
}
public function actions()
{
// return external action classes, e.g.:
return array(
'action1'=>'path.to.ActionClass',
'action2'=>array(
'class'=>'path.to.AnotherActionClass',
'propertyName'=>'propertyValue',
),
);
}
*/
public function actionsimpletree()
{
Yii::import('application.extensions.SimpleTreeWidget');
SimpleTreeWidget::performAjax();
}
}
and i have a model class
Tree
<?php
/**
-
The followings are the available columns in table ‘SampleDB.Tree’:
-
@property integer $id
-
@property integer $id_parent
-
@property string $tittle
-
@property integer $position
-
*/
class Tree extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @return Tree the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'SampleDB.Tree';
}
/**
* @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('id', 'required'),
//array('id, id_parent, position', 'numerical', 'integerOnly'=>true),
//array('tittle', 'length', 'max'=>45),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
//array('id, id_parent, tittle, position', 'safe', 'on'=>'search'),
array('id', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'idParent' => array(self::BELONGS_TO, 'Tree', 'id_parent'),
'trees' => array(self::HAS_MANY, 'Tree', 'id_parent'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'id_parent' => 'Id Parent',
'tittle' => 'Tittle',
'position' => 'Position',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
//$criteria->compare('id_parent',$this->id_parent);
//$criteria->compare('tittle',$this->tittle,true);
//$criteria->compare('position',$this->position);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}
}
And My view is
<?php
$this->breadcrumbs=array(
'Ajax',
);?>
<h1><?php echo $this->id . ‘/’ . $this->action->id; ?></h1>
<p>
You may change the content of this page by modifying
the file <tt><?php echo __FILE__; ?></tt>.
<tt>
<?php
//$this->widget(‘application.extensions.SimpleTreeWidget’,array(
// ‘model’=>‘Tree’,
//));
$this->widget(‘application.extensions.SimpleTreeWidget’,array(
//'model'=>Tree::model()->id, //Folder::model()->findByPk(43),
'model'=>'Tree',//::model()->findByPk(1),
'modelPropertyParentId' => 'parent_id',
//'modelPropertyName' => 'tittle',//'name',
//'modelPropertyId' => 'id',
'modelPropertyPosition' => 'position',
'ajaxUrl' => $this->createAbsoluteUrl('/ajax/simpletree'),
'onSelect'=>'
var id = data.inst.get_selected().attr("id").replace("node_","");
$("#contentBox").load("/ajax/getContent/id/"+id);
'
));
?>
</tt>.
</p>