0

I'm using Yii Bootstrap TbGridView to show a DataProvider from CSqlDataProvider. However, I can't display the value out to the screen. I don't know what happened. Here is my code:

Controller page:

$model = new ReportOptionForm('search');

$sql = 'SELECT c.client_id as "ProspectID", c.name as "ProspectName", count(t.activity_id) as "CallCount", c.created_on as "ProspectDate", con.name as "Consultant"';
$sql .= ' FROM clients c LEFT OUTER JOIN consultants con ON c.CIC = con.con_id LEFT OUTER JOIN client_activities t ON c.client_id = t.client_id';
$sql .= ' WHERE c.status = '.Client::TYPE_PROSPECT;

if(!($con_id == ''))
{
    $sql .= ' AND c.CIC ='. $con_num;
}

if(!($team == ''))
{
    $sql_count .= ' AND con.tm_id = '.$team;    
}

if (!($startTs == NULL) && !($endTs == NULL)) {
    $sql .= ' AND DATE(c.created_on) between "'.$startTs.'" and "'.$endTs.'"';
}               
$sql .= ' GROUP BY c.client_id';

$dataProvider = new CSqlDataProvider($sql, array(
            'totalItemCount' => 100,
            'keyField' => 'ProspectID',
            'sort' => array(
                    'defaultOrder'=>'ProspectID ASC',
            ),
            'pagination'=>array(
                    'pageSize'=>$pageSize,
            ),
        ));

$render = Yii::app()->request->isAjaxRequest ? 'renderPartial' : 'render';
$this->$render('prospect',array(
                'model'=>$model,
                'dataProvider'=>$dataProvider,
                'pageSize'=>$pageSize,
)); 

Prospect View page:

$gridWidget=$this->widget('bootstrap.widgets.TbGridView',array(
    'id'=>'report-grid',
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        array(
            'name'=>'No',
            'value'=>'$row+1',
            'htmlOptions'=>array('style'=>'text-align:center'),
        ),

        array('name'=>'Prospect Date', 'type'=>'raw', 'value'=>$data->ProspectDate),
        array('name'=>'Prospect Name', 'type'=>'raw', 'value'=>$data->ProspectName),
        'Consultant'        
    ),
)); 

I do the testing on the local server, there is no error, but the value that is looped by using:

array('name'=>'Prospect Date', 'type'=>'raw', 'value'=>$data->ProspectDate),

the value for this column is not diplayed. However, the column for 'Consultant', the value can be displayed. Another problem is when I uploaded the file into real server, error is given:

Undefined variable: data

where the data, refers to the $data->ProspectDate Can someone help me to figure it out, what is the problem?

Siguza
  • 21,155
  • 6
  • 52
  • 89
CnV
  • 381
  • 4
  • 20
  • did you try putting that $data->ProspectDate string in parenthesis? like so: ` ' array('name'=>'Prospect Name', 'type'=>'raw', 'value'=>'$data->ProspectDate')` – transient_loop Sep 08 '14 at 03:28
  • Hi, I tried like what you have suggested, on the local server, the value is still not displayed, and the error on the real server is gone. But new error message is appeared: Trying to get property of non-object – CnV Sep 08 '14 at 03:38
  • somehow it treats the ProspectDate in 'value'=>'$data->ProspectDate', as an object. – CnV Sep 08 '14 at 03:44
  • try looking exactly at $data, what's inside? – transient_loop Sep 08 '14 at 03:45
  • how can I check on that? – CnV Sep 08 '14 at 03:48
  • you could just print it out on screen or in your log file with error_log() or echo $data – transient_loop Sep 08 '14 at 03:48
  • when I just echo $data, i get this error: Either "name" or "value" must be specified for CDataColumn. – CnV Sep 08 '14 at 03:50
  • what appears if you just do 'value'=>'$data'? – transient_loop Sep 08 '14 at 03:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/60798/discussion-between-verlee-and-faboolous). – CnV Sep 08 '14 at 03:54
  • When I do 'value'=>'$data', both local server & real server will show the table and the value for the column shows Array – CnV Sep 08 '14 at 03:55
  • I get it fixed alr. Thank you. I dont know what, but somehow it's written like this: array('name'=>'Prospect Date', 'value'=>'$data["ProspectDate"]'), – CnV Sep 08 '14 at 04:18

0 Answers0