I’ll have to deploy a Yii application on a server where eval() is disabled (for security reasons). And I can’t make my application avoid using eval() without major changes. For instance it seems that CGridView depends on eval().
Apart from the ugliness of putting code in a string (hard not to forget a parenthesis), my problem is this code relies on eval(). Looking in the doc, I saw I coud probably define columns by extending CDataColumn, but this class still expects a "value" attribute that gets evaled. Is there a way to use a function that would receive $data as parameter? Something like:
class MyColumn extends CDataColumn
{
function getValue($data) // would be used instead of $this->value
{
return CHtml::link(
$data->keyword,
array("keyword/view", "id" => $data->id),
array("title" => $data->notes, "class" => "keyword")
);
}
I know someone posted on “eval() is evil” last month, especially thinking of HipHop, but contrary to this, I don’t want to delete the eval() uses from the Yii code, I’m just looking for a way to avoid it in my application.
If anyone has the same problem, it’s just that the documentation isn’t very clear. It says that the attributes “value” will be evaled. But Yii doesn’t use eval() but CComponent::evaluateExpression(). If given an array, it will behave like call_user_func_array().
and add your model in current context and parametrize it
public function myDataRender($data,$row,$grid){
$this->myCurrentModel->setSomeDataProperty($data->property);
return $this->myCurrentModel->renderSomeText($data->someProperty);
}
Thanks for your help. Yii cannot find the third argument for myDataRender: Missing argument 3 for MyController::myDataRender();
Can you please suggest how I can obtain the value of one of the CGrudView columns in myDataRender() according to which I would like to calculate which css class to display?