我使用Yii Bootstrap TbGridView显示来自CSqlDataProvider的DataProvider。但是,我无法将值显示在屏幕上。我不知道发生了什么。这是我的代码:
控制器页面:
$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,
));
展望视图页面:
$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'
),
));
我在本地服务器上进行测试,没有错误,但是通过使用循环的值:
array('name'=>'Prospect Date', 'type'=>'raw', 'value'=>$data->ProspectDate),
此列的值未显示。但是,可以显示' Consultant'的列。 另一个问题是当我将文件上传到真实服务器时,给出了错误:
Undefined variable: data
其中数据是指 $ data-> ProspectDate 有人可以帮我搞清楚,问题是什么?