Hi Guys,
a new problem I’ve found in connection with my virtual attribute, on admin page I can’t search in the gridtop search on NbspName, but I can in the advanced search.
What can be the problem?
I see: because in the advanced search, I search for the original name, and down at the gridtop search, it wants to search directly to NbspName, because the view looks like this:
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'model-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'id',
'NbspName',
...
however NbspName doesn’t really exist this way. Is there a way to make the gridtop search believe to search for a different value than what is shown in the columns section?
I tried to do this (looks straightforward to me):
public function search() {
...
$criteria->compare('name', $this->NbspName, true);
...
}
but no luck…
Thanks!
UPDATE: this way it’s good.
however, for now, I think every data is to use it, one would like to search for it, to handle it, etc so, I don’t really see the point of virtual attributes, but I’m just a beginner so maybe later I will find the real use of it.
ahh, still not completely good. I thought adding this:
$criteria->select = array("*", "CONCAT(REPEAT(' ', level), name) AS nbsp_name");
will solve the problem, but now all nbsps are printed as ‘ ’. how can I add the php function html_entity_decode to this custom column?
UPDATE: I have found another solution:
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'uzem-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'id',
array(
'name' => 'nbsp_name',
'type' => 'raw',
),
...
this way, the nbsps are rendered normally.
and for the related table’s create _form I still need a magic GET function also, otherwise the dropdown is not working. 
BEWARE: the variable name and the function name (without the ‘get’ part) must not be the same!
but now at last everything is working.
Thanks
c