使用yiicgridview
Parse error: syntax error, unexpected T_FUNCTION in /home/.../result.php on line 23
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-table',
'dataProvider'=>$model->search(),
'columns'=>array(
array('header' => '#','value'=>'$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)','headerHtmlOptions'=>array('class'=>'table-header-check')),
array('name'=>'testname'),
array('header'=> 'Subject Name','value'=>'$data->sub->subname'),
array('header'=>'Validity', 'value'=>'$data->testfrom." To ".$data->testto'),
array('header'=>'attemptedstudents',
'value'=>function($data){
$dataReader = Yii::app()->db->createCommand('SELECT COUNT(stdid)as atstd FROM studenttest WHERE testid='.$data->testid.' AND status ="over"')->query();
$atStd = $dataReader->read();
return $atStd['atstd']; }),
array('header'=>'Details',
'class'=>'CButtonColumn',
'template'=>'{details}',
'buttons' => array (
'details' =>array('imageUrl'=>Yii::app()->request->baseUrl.'/css/images/detail.png',
'url'=>'Yii::app()->createUrl("test/resultdetail", array("testid"=>$data->testid))',
'options'=>array( 'class'=>'icon-manage')),
),
),
),
'itemsCssClass' => 'table table-striped table-bordered bootstrap-datatable datatable',
'cssFile'=>false,
));?>
错误行代码为'array('header'=>'attemptedstudents','value'=>function($data){';
但是这段代码在XAMP本地主机上完美运行。
但它上传到服务器我收到此错误。
任何人请指导我..
答案 0 :(得分:2)
如果您使用Anonymous functions,则需要PHP> = 5.3
答案 1 :(得分:0)
你不能直接在那里写复杂的函数。写一个函数 模型或控制器,然后调用该函数。
请参考
http://www.yiiframework.com/wiki/278/cgridview-render-customized-complex-datacolumns/
答案 2 :(得分:0)
试试此代码
array('header' => 'attemptedstudents', 'value' => array($this, 'getData')
在控制器
中public function getData($data) {
$dataReader = Yii::app()->db->createCommand('SELECT COUNT(stdid)as atstd FROM studenttest WHERE testid=' . $data->testid . ' AND status ="over"')->query();
$atStd = $dataReader->read();
return $atStd['atstd'];
}