Hello everyone. Still fairly new to Yii and loving nearly everything about it, but I am trying to get a grasp on all the things it can do. So I started a demo application where I am plugging in a lot the non-standard (for me) elements such as CTreeView.
I have found and read a number of examples and documentation pages, but I am still having trouble. My big issue (which seems simple) is setting a branch to start collapsed. I don’t know what restriction there are to do this but I can’t even seem to get the simplest example working. In fact, I download an app that demoed these and got the same problem. The error I am getting is as follows.
PHP Error
Undefined index: css
C:\...\yiiframework\framework\web\widgets\CTreeView.php(211)
199 if(isset($node['hasChildren']) && $node['hasChildren'])
200 {
201 if($css!=='')
202 $css.=' ';
203 $css.='hasChildren';
204 }
205
206 $options=isset($node['htmlOptions']) ? $node['htmlOptions'] : array();
207 if($css!=='')
208 {
209 if(isset($options['css']))
210 $options['css'].=' ';
211 $options['css'].=$css; // HERE IS WHERE THE ERROR IS AT
212 }
213
214 if(isset($node['id']))
215 $options['id']=$node['id'];
216
217 $html.=CHtml::tag('li',$options,$node['text'],false);
218 if(!empty($node['children']))
219 {
220 $html.="\n<ul>\n";
221 $html.=self::saveDataAsHtml($node['children']);
222 $html.="</ul>\n";
223 }
but I have determined that it happens ONLY when I try setting the ‘expanded’ setting on a branch. Here is my data tree and CTreeView widget run.
$dataArray = array(
array('text'=>'First','children'=>array(
array('text'=>'Some Point', ),
array('text'=>'Another Point', 'children'=>array(
array('text'=>'Sub points are good', 'children'=>array(
array('text'=>'Like this'),
array('text'=>'Or even like this'),
)),
array('text'=>'Sub points are bad'),
array('text'=>'Sub points are sub points'),
)),
array('text'=>'More stuff'),
array('text'=>'Also this'),
)),
array('text'=>'Second'),
array('text'=>'Third', 'children'=>array(
array('text'=>'It goes on', ),
array('text'=>'and on...', 'children'=>array(
array('text'=>'and on...', 'children'=>array(
array('text'=>'and on...', 'expanded'=>false, 'children'=>array( // HERE - 'expanded'=>false - IS WHAT CAUSES THE ERROR
array('text'=>'and then stops'),
)),
)),
)),
)),
);
$this->widget('CTreeView', array(
'data'=>$dataArray,
'htmlOptions'=>array('class'=>'treeview-red'),
));
as you can see, I am not trying to do much of anything fancy here, I just need to be able to set these from starting in the open position.
What am I doing wrong?