Home > PHP Framework > YII > How to introduce other templates into the content template page in yii2

How to introduce other templates into the content template page in yii2

王林
Release: 2020-02-17 14:31:42
Original
2016 people have browsed it

How to introduce other templates into the content template page in yii2

In the view file, such as the view file of user.php.

<?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>
Copy after login

(Related tutorial recommendation: yii framework)

Use:

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

for introduction. It should be noted that the output statement is used before render. Echo displays the content of the subtemplate. The parameters are used in the same way as in the action. The @app template variable represents the main folder.

The sub-template code is as follows:

<?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>
Copy after login

For more programming-related content, please pay attention to the Programming Tutorial column of the php Chinese website!

The above is the detailed content of How to introduce other templates into the content template page in yii2. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
yii2 error connecting to mongodb3.2.4
From 1970-01-01 08:00:00
0
0
0
How to use mongodb to do rbac in yii2
From 1970-01-01 08:00:00
0
0
0
php - yii2-ueditor-widget
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template