Rumah  >  Artikel  >  rangka kerja php  >  yii2怎么将其他模板引入内容模板页面

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

王林
王林asal
2020-02-17 14:31:421945semak imbas

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

在view文件中,如user.php的view文件。

<?php
defined(&#39;YII_ENV&#39;) or exit(&#39;Access Denied&#39;);
 
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/27
 * Time: 11:18
 */
 
use yii\widgets\LinkPager;
 
$urlManager = Yii::$app->urlManager;
$this->title = &#39;业务员列表&#39;;
$this->params[&#39;active_nav_group&#39;] = 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([&#39;mch/salesman/salesman-edit&#39;]) ?>">添加业务员</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[&#39;id&#39;]?></span>              
                    </td>
                    <td><?= $val[&#39;mobile&#39;] ?></td>
                    <td><?= $val[&#39;truename&#39;] ?></td>
                    <td><?= $val[&#39;user_id&#39;];?></td>
                     <td><?= Yii::$app->formatter->asDatetime($val[&#39;edittime&#39;],"Y-M-d H:m");?></td>
                    <td>
                        <a class="btn btn-sm btn-primary"
                           href="<?= $urlManager->createUrl([&#39;mch/salesman/salesman-edit&#39;, &#39;id&#39; => $val[&#39;id&#39;]]) ?>">修改</a>
                        <a class="btn btn-sm btn-danger del"
                           href="<?= $urlManager->createUrl([&#39;mch/salesman/salesman-del&#39;, &#39;id&#39; => $val[&#39;id&#39;]]) ?>">删除</a>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        <?php echo $this->render(&#39;@app/views/layouts/paginator.php&#39;,[&#39;pagination&#39;=>$pagination]);?>
    </div>
</div>
<script>
    $(document).on(&#39;click&#39;, &#39;.nav-item1&#39;, function () {
        if($(this).find(".trans")[0].style.display==&#39;inline-block&#39;){
            $(this).find(".trans")[0].style.display=&#39;inline&#39;;
        }else{
            $(this).find(".trans")[0].style.display=&#39;inline-block&#39;;
        }
        $(&#39;.bg-&#39;+$(this).index(".nav-item1")).toggle();
    }); 
    $(document).on(&#39;click&#39;, &#39;.del&#39;, function () {
        if (confirm("是否删除该记录,删除后不可恢复?")) {
            $.ajax({
                url: $(this).attr(&#39;href&#39;),
                type: &#39;get&#39;,
                dataType: &#39;json&#39;,
                success: function (res) {
                    alert(res.msg);
                    if (res.code == 0) {
                        window.location.reload();
                    }
                }
            });
        } 
        return false;
    });
</script>

(相关教程推荐:yii框架

使用:

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

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

子模板代码如下:

<?php use yii\widgets\LinkPager;?>
<div class="text-center">
	<nav aria-label="Page navigation example">
        <?php
            echo LinkPager::widget([
            &#39;pagination&#39; => $pagination,
            &#39;prevPageLabel&#39; => &#39;上一页&#39;,
            &#39;nextPageLabel&#39; => &#39;下一页&#39;,
            &#39;firstPageLabel&#39; => &#39;首页&#39;,
            &#39;lastPageLabel&#39; => &#39;尾页&#39;,
            &#39;maxButtonCount&#39; => 5,
            &#39;options&#39; => [
                &#39;class&#39; => &#39;pagination&#39;
            ],
            &#39;prevPageCssClass&#39; => &#39;page-item&#39;,
            &#39;pageCssClass&#39; => "page-item",
            &#39;nextPageCssClass&#39; => &#39;page-item&#39;,
            &#39;firstPageCssClass&#39; => &#39;page-item&#39;,
            &#39;lastPageCssClass&#39; => &#39;page-item&#39;,
            &#39;linkOptions&#39; => [
                &#39;class&#39; => &#39;page-link&#39;
            ],
            &#39;disabledListItemSubTagOptions&#39; => [
                &#39;tag&#39; => &#39;a&#39;,
                &#39;class&#39; => &#39;page-link&#39;
            ]
        ])?>
    </nav>
	<div class="text-muted">共<?= $pagination->totalCount ?>条数据</div>
</div>

更多编程相关内容学习,请关注php中文网编程教程栏目!

Atas ialah kandungan terperinci yii2怎么将其他模板引入内容模板页面. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:yii2.0怎么绑定事件Artikel seterusnya:yii实现不调用layout布局文件