如何使用Yii从打印机直接打印? [英] How to print directly from printer with Yii?

查看:191
本文介绍了如何使用Yii从打印机直接打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何直接从打印机打印?

How do I print directly from printer?

这是一个Intranet Web应用程序.用户将使用此应用程序,他们将从其部门的打印机(不同部门,不同的打印机)中打印出报告.我正在谷歌搜索直接从打印机打印出来,但找不到任何地方.我正在使用Yii Framework 1.11.

This is a intranet web application. The user will use this application and they will print out the report from the printer of their department (different department, different printer). I'm Googling to print out directly from printer, but I can't find anywhere. I'm using Yii Framework 1.11.

我该怎么做?是否可以直接从打印机打印出来?怎么样?

How can I do this? Is it possible to print out directly from printer? How?

推荐答案

至少我找到了最好的方法.我从以下站点获得了js.

AT least I fount the best way. I got the js from following site.

http://www .position-absolute.com/articles/printing-web-pages-a-new-jquery-printing-plugin/

我的视图(索引或其他内容)

My View (index or something)

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

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>

这篇关于如何使用Yii从打印机直接打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆