Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 打印CGridView-Yii_Php_Printing_Yii_Cgridview - Fatal编程技术网

Php 打印CGridView-Yii

Php 打印CGridView-Yii,php,printing,yii,cgridview,Php,Printing,Yii,Cgridview,我正试图让打印机在按钮上打印我的CGridView。 我的观点 <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

我正试图让打印机在按钮上打印我的CGridView。
我的观点

<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 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)


不
工作编号。
日期
部门
部分
团队
但是使用上面的代码,我收到一个未定义索引的错误:all
这将如何工作

试试这个

Yii::app()->session['all'] 

不是直接访问$\u会话

您在哪里声明了$\u会话['all']?您正在模型中使用它,但尚未定义它。Yii::app()->session['all']。增加这一行怎么样?您尝试过这个吗?类似地,您可以像$d=Yii::app()->session['var']@RafayZiaMir那样使用它,但我正在尝试获取foreach的非对象属性。bcz“->”用于访问对象的属性,而不是数组。因为数据是数组索引,所以您可以作为Yiiapp()->session['all']['data']访问。如果出现错误,请尝试调试会话。写入CVarDumper::Dump(Yiiapp()->session['all'],100,true),die(),它将显示session数组的内容。然后发布您得到的结果(在您的问题中),它工作了,但现在我正在尝试获取foreach的非对象属性。这是因为控制器中的赋值是在调用搜索方法之前设置的,请尝试在控制器中的赋值之前调用搜索,看看会发生什么。
<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>
Yii::app()->session['all']