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

Feb 17, 2020 pm 02:31 PM
yii2 template

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to add PPT mask How to add PPT mask Mar 20, 2024 pm 12:28 PM

Regarding PPT masking, many people must be unfamiliar with it. Most people do not understand it thoroughly when making PPT, but just make it up to make what they like. Therefore, many people do not know what PPT masking means, nor do they understand it. I know what this mask does, and I don’t even know that it can make the picture less monotonous. Friends who want to learn, come and learn, and add some PPT masks to your PPT pictures. Make it less monotonous. So, how to add a PPT mask? Please read below. 1. First we open PPT, select a blank picture, then right-click [Set Background Format] and select a solid color. 2. Click [Insert], word art, enter the word 3. Click [Insert], click [Shape]

Effects of C++ template specialization on function overloading and overriding Effects of C++ template specialization on function overloading and overriding Apr 20, 2024 am 09:09 AM

C++ template specializations affect function overloading and rewriting: Function overloading: Specialized versions can provide different implementations of a specific type, thus affecting the functions the compiler chooses to call. Function overriding: The specialized version in the derived class will override the template function in the base class, affecting the behavior of the derived class object when calling the function.

How to remove jquery in yii2 How to remove jquery in yii2 Feb 17, 2023 am 09:55 AM

How to remove jquery from yii2: 1. Edit the AppAsset.php file and comment out the "yii\web\YiiAsset" value in the variable $depends; 2. Edit the main.php file and add the configuration "'yii" under the field "components" \web\JqueryAsset' => ['js' => [],'sourcePath' => null,]," to remove the jquery script.

PHP email templates: customize and personalize your email content. PHP email templates: customize and personalize your email content. Sep 19, 2023 pm 01:21 PM

PHP email templates: Customize and personalize your email content With the popularity and widespread use of email, traditional email templates can no longer meet people's needs for personalized and customized email content. Now we can create customized and personalized email templates by using PHP programming language. This article will show you how to use PHP to achieve this goal, and provide some specific code examples. 1. Create an email template First, we need to create a basic email template. This template can be an HTM

How to use templates in OneNote to improve productivity How to use templates in OneNote to improve productivity Apr 30, 2023 am 11:31 AM

Did you know that using templates can make you faster at note-taking and more effective at capturing important ideas? OneNote has a set of ready-made templates for you to use. The best part is that you can also design the template according to your needs. Whether you are a student, a corporate warrior or a freelancer doing creative work. OneNote templates can be used to record important notes in a structure and format that suits your style. A template can be an outline of a note-taking process. Amateurs just take notes, professionals take notes and draw connections from them through well-structured notes with the help of templates. Let's see how to use templates in OneNote. Use Default OneNote Template Step 1: Press Windows+R on your keyboard. Type Oneno

Template Metaprogramming in C++ FAQ Interview Questions Template Metaprogramming in C++ FAQ Interview Questions Aug 22, 2023 pm 03:33 PM

C++ is a programming language widely used in various fields. Its template metaprogramming is an advanced programming technique that allows programmers to transform types and values ​​at compile time. Template metaprogramming is a widely discussed topic in C++, so questions related to it are quite common in interviews. Here are some common template metaprogramming interview questions in C++ that you may be asked. What is template metaprogramming? Template metaprogramming is a technique for manipulating types and values ​​at compile time. It uses templates and metafunctions to generate based on types and values

Flask-Bootstrap: Add templates to Flask applications Flask-Bootstrap: Add templates to Flask applications Jun 17, 2023 pm 01:38 PM

Flask-Bootstrap: Adding templates to Flask applications Flask is a lightweight Python web framework that provides a simple and flexible way to build web applications. It is a very popular framework, but its default templates have limited functionality. To create attractive user interfaces, use additional frameworks or libraries. This is where Flask-Bootstrap comes in. Flask-Bootstrap is a Twitter-based

How to implement image template and mask processing in Vue? How to implement image template and mask processing in Vue? Aug 17, 2023 am 08:49 AM

How to implement image template and mask processing in Vue? In Vue, we often need to perform some special processing on images, such as adding template effects or masks. This article will introduce how to use Vue to achieve these two image processing effects. 1. Image template processing When using Vue to process images, we can use the filter attribute of CSS to achieve template effects. The filter attribute adds graphic effects to the element, and the brightness filter can change the brightness of the picture. we can change

See all articles