总结
豆包 AI 助手文章总结
首页 > php框架 > YII > 正文

yii如何引用模板

藏色散人
发布: 2020-01-09 10:09:03
原创
2113人浏览过

yii如何引用模板

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 yii\widgets\LinkPager;
 
$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>
登录后复制

使用

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

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

 

子模板代码如下:

<?php use yii\widgets\LinkPager;?>
<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>
登录后复制

以上就是yii如何引用模板的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
豆包 AI 助手文章总结
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号