0

使用时出现以下错误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 本地主机中运行良好。但它上传到服务器我收到此错误。任何人请指导我..

4

3 回答 3

2

如果您使用匿名函数,则需要 PHP >= 5.3

于 2013-10-25T11:53:51.517 回答
0

您不能直接在那里编写复杂的函数。在模型或控制器中编写一个函数,然后调用该函数。

请参考

http://www.yiiframework.com/wiki/278/cgridview-render-customized-complex-datacolumns/

于 2013-10-25T11:30:39.960 回答
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'];
}
于 2013-10-25T11:35:54.950 回答