Question

I am trying to get my CGridView printed by a printer on a button.
My View

<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,
...)); ?>

My Controller

public function actionPrint() {
        $d = $_SESSION['all'];
        $this->renderPartial('print',array('d'=>$d),false,true);
}

My model

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;
    }

My view (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>

But using the above code i am receiving an error of Undefined index: all
How will this work.

Was it helpful?

Solution

try this

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

instead of accessing the $_SESSION directly

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top