I am trying to list values from a treview in a dropdown list, in Yii. So, i already have a function to concatenate the treeview in path like (example primary\secondary\terciary. I call this function passing the ID from the data and the function select the parents, creating list from the database.
public static function getPath($id) {
$post=PlanoAssunto::model()->find('id=:id', array(':id'=>$id));
if ($post->id_pai == null) {
$row=$post->assunto;
$data= $row;
}
else {
$row=$post->assunto;
$row=PlanoAssunto::getPath($post->id_pai).'/'.$row;
$data= $row;}
if (isset($data)) {
return $data;
}
else {
$data = 'Nulo';
return $data;
}
}
This work fine in a view, using this:
<?php echo $form->labelEx($model,'id_pai');?>
<?php if (isset($_GET['id'])){
echo PlanoAssunto::model()->getPath($_GET['id']); }
else { echo "Novo Assunto Principal";}
?>
But now i want to populate a select, in the form, with the path list. And I cant run functions inside CHtml::listData. I am trying with this ih the model, with no success:
public static function getTypeOptions() {
return CHtml::listData(PlanoAssunto::model()->findAll(),'id','getPath($id)');
}
So, what I am doing wrong? I cant manage a way to put a treeview in path format in the value, associated to his id in database.
I cant figure how I can fill the values in ListData, my HTML returns the IDs, but with any data in value.
<select name="Areaxplanoassunto[idAssunto]" id="Areaxplanoassunto_idAssunto">
<option value="1"></option>
<option value="2"></option>
<option value="3"></option>
<option value="4"></option>
<option value="5"></option>
<option value="6"></option>
<option value="7"></option>
<option value="9"></option>
<option value="10"></option>
<option value="11"></option>
</select>
Tks. (I am from Brasil, so sorry for the english)