我想讓我的CGridView按鈕上的打印機打印。
我的視圖打印CGridView - Yii
<p align="right">
<?php
echo CHtml::link('New Job',array('create'),array('class'=>'btn btn-info'));
echo CHtml::link('Print',array('print'),array('class'=>'btnPrint btn btn-info', 'style'=>'margin-left: 10px;'));
?>
</p>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'job-grid',
'dataProvider'=>$jobs->search(),
'filter'=>$jobs,
...)); ?>
我的控制器
public function actionPrint() {
$d = $_SESSION['all'];
$this->renderPartial('print',array('d'=>$d),false,true);
}
我的模型
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id,true);
$criteria->compare('name',$this->name,true);
$criteria->compare('date',$this->date,true);
$criteria->compare('department_id',$this->department_id);
$criteria->compare('section_id',$this->section_id);
$criteria->compare('team_id',$this->team_id);
$criteria->compare('created_date',$this->created_date,true);
$criteria->compare('updated_date',$this->updated_date,true);
$data = new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
'pagination'=>false,
));
$_SESSION['all'] = $data;
$data = new CActiveDataProvider(get_class($this), array(
'pagination'=>array('pageSize'=> Yii::app()->user->getState('pageSize',
Yii::app()->params['defaultPageSize']),),
'criteria'=>$criteria,
));
$_SESSION['limited'] = $data;
return $data;
}
我的視圖(print.php)
<div id="summary">
<table width="100%" border="1">
<tr>
<th>No.</th>
<th>Job No.</th>
<th>Date</th>
<th>Department</th>
<th>Section</th>
<th>Team</th>
</tr>
<?php
$i=1;
foreach($d->data as $item)
{
?>
<tr>
<td><?php echo $i;?></td>
<td><?php echo $item->name; ?></td>
<td><?php echo $item->date; ?></td>
<td><?php echo $item->departmentsdep->name; ?></td>
<td><?php echo $item->departmentssec->name; ?></td>
<td><?php echo $item->departmentstea->name; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
</div>
但如果使用上面的代碼我收到未定義指數的錯誤:所有
如何將這項工作。
你宣佈$ _SESSION [ '所有']在哪裏?您在模型中使用它,但尚未定義它。 –
Yii :: app() - > session ['all']。那麼添加這條線呢?你試過這個嗎? –
同樣,你可以像使用它$ d = Yii :: app() - > session ['var'] –