Is there a global setting in Yii to change the htmlentity display from "©" to "©"
for admin(ajax grid)/view/ and edit views?
I found that in the CGridView parameters, I can go and update each column to 'type'=>'raw' like below, but I will need to do this in twenty Models, and and each view manually unless I can do its globally somewhere. I have a script that imports the data with ©, and when the customers go to edit an item, they would like to see ©. Any help is appritiated!
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'item-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'price1',
'price1label',
'price2',
'price2label',
array('name'=>'name','type'=>'raw'), // this will display the raw entity
There’s no such functionality built into Yii, but as is usually the case you can extend a couple of classes to achieve the aim.
First off, note that this is the property whose default value you ‘d like to change. If you could¹ do that, then all the problems would go away.
Since you can’t, you need to extend
CDataColumnto achieve this. Dead simple:Now the problem is that you also need to tell Yii to use your special column class instead of the built-in. You can do this by specifying the
typeof each column in theCGridViewinstantiation, but that’s not acceptable because you still have the problem of needing to edit every column in every view. So we ‘ll have to look into howCGridViewdecides to use aCDataColumnand override that.Grepping a little shows that this is the code you need to modify. Specifically, there are two lines of interest:
and
So, you need to override the
createDataColumnmethod (to change what the first line does) and theinitColumnsmethod (to edit the second line). Here we go:After this is done, you are just one more edit away from happiness:
You still need to make this edit in every view that uses a data grid, but that shouldn’t take more than a few seconds with find/replace.
¹ Actually, you can simply go to that file inside the framework sources, edit a few characters, save, problem solved. The problem with this approach is that if you upgrade to a later version of Yii, your application will revert to the old behavior without warning. I don’t recommend it.