yii如何引用模板?
在yii2中內容模板頁面引入其他模板的方法
推薦學習:yii框架
在yii2中內容模板頁面引入其他模板的方法
?
在view文件中,如user.php的view文件。
<?php defined('YII_ENV') or exit('Access Denied'); /** * Created by PhpStorm. * User: Administrator * Date: 2019/8/27 * Time: 11:18 */ use yiiwidgetsLinkPager; $urlManager = Yii::$app->urlManager; $this->title?=?'業務員列表'; $this->params['active_nav_group']?=?2; ?> ? <div> ????<div> ????????<span>=?$this->title??></span> ????????<ul> ????????????<li> ????????????????<a>createUrl(['mch/salesman/salesman-edit'])??>">添加業務員</a> ????????????</li> ????????</ul> ????</div> ????<div> ????????<table> ????????????<thead> ????????????<tr> ????????????????<th>ID</th> ????????????????<th>手機</th> ????????????????<th>姓名</th> ????????????????<th>綁定用戶</th> ????????????????<th>修改時間</th> ????????????????<th>操作</th> ????????????</tr> ????????????</thead> ????????????<tbody> ????????????<?php foreach ($list as $index =>?$val)?:??> ????????????????<tr> ????????????????????<td> ????????????????????????<span>=?$val['id']?></span>?????????????? ????????????????????</td> ????????????????????<td>=?$val['mobile']??></td> ????????????????????<td>=?$val['truename']??></td> ????????????????????<td>=?$val['user_id'];?></td> ?????????????????????<td>=?Yii::$app->formatter->asDatetime($val['edittime'],"Y-M-d?H:m");?></td> ????????????????????<td> ????????????????????????<a>createUrl(['mch/salesman/salesman-edit',?'id'?=>?$val['id']])??>">修改</a> ????????????????????????<a>createUrl(['mch/salesman/salesman-del',?'id'?=>?$val['id']])??>">刪除</a> ????????????????????</td> ????????????????</tr> ????????????<?php endforeach; ?> ????????????</tbody> ????????</table> ????????<?php echo $this->render('@app/views/layouts/paginator.php',['pagination'=>$pagination]);?> ????</div> </div> <script> $(document).on('click', '.nav-item1', function () { if($(this).find(".trans")[0].style.display=='inline-block'){ $(this).find(".trans")[0].style.display='inline'; }else{ $(this).find(".trans")[0].style.display='inline-block'; } $('.bg-'+$(this).index(".nav-item1")).toggle(); }); $(document).on('click', '.del', function () { if (confirm("是否刪除該記錄,刪除后不可恢復?")) { $.ajax({ url: $(this).attr('href'), type: 'get', dataType: 'json', success: function (res) { alert(res.msg); if (res.code == 0) { window.location.reload(); } } }); } return false; }); </script>
使用
<?php echo $this->render('@app/views/layouts/paginator.php',['pagination'=>$pagination]);?>
進行引入,要注意的是,在render前使用輸出語句echo,顯示子模板內容,參數的使用同在action中,@app模板變量代表主文件夾。
?
子模板代碼如下:
<?php use yiiwidgetsLinkPager;?><div> <nav> ????????<?php echo LinkPager::widget([ 'pagination' =>?$pagination, ????????????'prevPageLabel'?=>?'上一頁', ????????????'nextPageLabel'?=>?'下一頁', ????????????'firstPageLabel'?=>?'首頁', ????????????'lastPageLabel'?=>?'尾頁', ????????????'maxButtonCount'?=>?5, ????????????'options'?=>?[ ????????????????'class'?=>?'pagination' ????????????], ????????????'prevPageCssClass'?=>?'page-item', ????????????'pageCssClass'?=>?"page-item", ????????????'nextPageCssClass'?=>?'page-item', ????????????'firstPageCssClass'?=>?'page-item', ????????????'lastPageCssClass'?=>?'page-item', ????????????'linkOptions'?=>?[ ????????????????'class'?=>?'page-link' ????????????], ????????????'disabledListItemSubTagOptions'?=>?[ ????????????????'tag'?=>?'a', ????????????????'class'?=>?'page-link' ????????????] ????????])?> ????</nav><div>共=?$pagination->totalCount??>條數據</div> </div>
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END