Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am getting the following error while using 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,    
));?>

The error line code is 'array('header'=>'attemptedstudents','value'=>function($data){'; But this code is working perfectly in the XAMP local host. But it uploaded to server i am getting this error. Any one please guide me ..

share|improve this question
    
check your php version in XAMPP using <?php phpinfo(); ?> and compare it with your production/live server's PHP version. –  Latheesan Oct 25 '13 at 11:28
    
Discover debug –  Alma Do Oct 25 '13 at 11:28
    
'value'=>'$data->testfrom." To ".$data->testto' - This string is incorrectly escaped - The values $data will not be resolved –  AlexP Oct 25 '13 at 11:29
1  
This question appears to be off-topic because it is about syntax error. –  tereško Oct 25 '13 at 11:32
3  
@akhilnl, If you are using Anonymous functions you require PHP >= 5.3, perhaps the server is not on the same version? –  AlexP Oct 25 '13 at 11:35

3 Answers 3

up vote 2 down vote accepted

If you are using Anonymous functions you require PHP >= 5.3

share|improve this answer

You can't write complex functions directly there. Write a function in model or controller and then call that function instead.

please refer

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

share|improve this answer
    
but it is working in the XAMP ... –  akhil n l Oct 25 '13 at 11:32

Try this code

array('header' => 'attemptedstudents', 'value' => array($this, 'getData')

In Controller

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'];
}
share|improve this answer
    
Ya it will work thanks man ...But the real problem is the Php versions difference .. –  akhil n l Oct 25 '13 at 11:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.