最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

yii2怎么将其他模板引入内容模板页面

来源:动视网 责编:小采 时间:2020-11-03 18:18:18
文档

yii2怎么将其他模板引入内容模板页面

yii2怎么将其他模板引入内容模板页面:在view文件中,如user.php的view文件。<php defined('YII_ENV') or exit('Access Denied'); /** * Created by PhpStorm. * User: Administrator * Date: 2019/8/27 * Time: 11:1
推荐度:
导读yii2怎么将其他模板引入内容模板页面:在view文件中,如user.php的view文件。<php defined('YII_ENV') or exit('Access Denied'); /** * Created by PhpStorm. * User: Administrator * Date: 2019/8/27 * Time: 11:1


在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 class="panel mb-3">
 <div class="panel-header">
 <span><?= $this->title ?></span>
 <ul class="nav nav-right">
 <li class="nav-item">
 <a class="nav-link" href="<?= $urlManager->createUrl(['mch/salesman/salesman-edit']) ?>">添加业务员</a>
 </li>
 </ul>
 </div>
 <div class="panel-body">
 <table class="table table-bordered bg-white">
 <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 class="nav-item1">
 <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 class="btn btn-sm btn-primary"
 href="<?= $urlManager->createUrl(['mch/salesman/salesman-edit', 'id' => $val['id']]) ?>">修改</a>
 <a class="btn btn-sm btn-danger del"
 href="<?= $urlManager->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>

(相关教程推荐:yii框架)

使用:

<?php echo $this->render('@app/views/layouts/paginator.php',['pagination'=>$pagination]);?>

进行引入,要注意的是,在render前使用输出语句echo,显示子模板内容,参数的使用同在action中,@app模板变量代表主文件夹。

子模板代码如下:

<?php use yiiwidgetsLinkPager;?>
<div class="text-center">
	<nav aria-label="Page navigation example">
 <?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 class="text-muted">共<?= $pagination->totalCount ?>条数据</div>
</div>

更多编程相关内容学习,请关注Gxlcms编程教程栏目!

文档

yii2怎么将其他模板引入内容模板页面

yii2怎么将其他模板引入内容模板页面:在view文件中,如user.php的view文件。<php defined('YII_ENV') or exit('Access Denied'); /** * Created by PhpStorm. * User: Administrator * Date: 2019/8/27 * Time: 11:1
推荐度:
标签: 导入 页面 另一个
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top