Hello everyone. I’m using a CGridView with a data provider (CArrayDataProvider) and it’s working fine, but, one of the columns content is a link that it’s not working and I would appreciate your help to troubleshoot this issue.
The CGridView definition is like this:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'name'=>'column1',
// call the method 'getLink' from a model.
'value'=>array($model, 'getLink'),
'type'=>'html',
),
),
));
The function in the model, is defined like this:
public function getLink($data, $row)
{
return CHtml::beginForm() . CHtml::hiddenField("param1", $data["param1"]) . CHtml::linkButton($data["param1"], array("submit"=>array("customview2"))) . CHtml::endForm();
}
Everything seems to be working fine except for one thing. If I set ‘type’=>‘text’ in the CGridView column, the “HTML text” is displaying as expected, like:
<form action="/webapp/customview1" method="post"><input type="hidden" value="700" name="param1" id="param1" /><a href="#" id="yt1">700</a></form>
But, if I set ‘type’=>‘html’ in the CGridView column, the rendered HTML is displaying only the link. Checking the page source code shows this:
<a href="#">700</a>
and of course, the link doesn’t work because it doesn’t have the required html form tags.
From what I see, the CGridView is striping out the form HTML tags, maybe because as a security feature, in which case I don’t understand why it’s doing that when I am specifying that it is an “html” column.
I would really appreciate all your ideas to solve this "mistery".
Thank you in advance!
Edit: I just made a simpler test, and if I set the "value" of the column to be just:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'name'=>'column1',
'value'=>'"<form><b>Hello</b></form>"',
'type'=>'html',
),
),
));
The page outputs only "<b>Hello</b>" (displays Hello in bold, but the other tags are missing)… what is happening with the other tags? How can I stop this behavior? How can I use any tags that I want there?
Thank you!