师阳
- 师阳 2018-04-10 已签到连续签到1天,获得了5个金钱
- 师阳 2018-04-07 已签到连续签到1天,获得了5个金钱
- 师阳 2018-04-05 已签到连续签到1天,获得了5个金钱
- 师阳 2018-04-01 已签到连续签到1天,获得了5个金钱
- 师阳 2018-03-29 已签到连续签到5天,获得了20个金钱
- 师阳 回答了问题 widget 局部刷新的问题?
我觉得你可以把页面传进 widget 里,而不是把 model 传进去。或者不使用 widget。
我提供一种解决方案。
在 SellController.php 控制器里:
public function actionPrint($id) { $this->layout = false; //禁用布局 $model = Sell::findOne($id); //这里需要补上其它代码,比如访问权限判断,找不到这个 model 等等。 return $this->render('print', [ 'model' => $model, ]); }
在
sell/print.php
视图中:<?= $model->title ?> <?= $model->content ?>
以上我们完成了一些准备工作。这样以来,当我们通过 ajax 请求
sell/print
路由时,会返回sell/print.php
这个视图,这个视图根据 model 来生成的发票内容,你自己再调整样式。然后,再其它你需要进行发票打印的地方。比如在某个
index.php
视图文件里,你加上如下代码:<?php use yii\bootstrap\Modal; ?> <script> function printBill(id) { $.ajax({ type:'GET', url:"<?=\yii\helpers\Url::to(['sell/print'])?>" + "?id="+id, success:function(html){ $('#solution-content').html(html); $('#solution').modal('show'); } }); } </script> <?php Modal::begin([ 'header' => '<h3>发票</h3>', 'options' => ['id' => 'solution'] ]); ?> <div id="solution-content"> </div> <?php Modal::end(); ?>
这样一来,当你调用
printBill(id)
时,会把<div id="solution-content"> </div>
这部分的内容替换成
sell/print.php
这个视图的内容。并通过 Modal 框显示出来(你也可以不用 Modal 框,我这只是举例)。核心还是在:$.ajax({ type:'GET', url:"<?=\yii\helpers\Url::to(['sell/print'])?>" + "?id="+id, success:function(html){ $('#solution-content').html(html); // 这里 } });
- 师阳 2018-03-28 已签到连续签到4天,获得了20个金钱
- 师阳 2018-03-26 已签到连续签到2天,获得了10个金钱