Home Backend Development PHP Tutorial Detailed explanation of steps to display thinkPHP controller variables in templates

Detailed explanation of steps to display thinkPHP controller variables in templates

May 17, 2018 pm 02:10 PM
php thinkphp controller

This time I will bring you a detailed explanation of the steps for displaying thinkPHP controller variables in the template. What are the precautions for displaying thinkPHP controller variables in the template? The following is a practical case, let's take a look.

Variables in the controller

public function register() {
  $type = I("param.type");//1.学生注册 2.教师注册 3.其他注册
  $this -> assign("type", $type);
    //q全部部门
  $depart1 = M("Depart") -> where("status=1 and fid=0") -> order("id asc") -> select();
  $this -> assign("depart1", $depart1);
  $this -> display();
}
Copy after login

Reference position one in the template: In the php code, use $i; directly

<php>
  echo $i;
</php
Copy after login

Reference position two in the template: Apply directly in the template {$i} or class="{$unlogined}"

<font color="red">注意:1.非相关人员,严禁注册。{$i}</font><br>
<php>
  $logined = is_array($_SESSION['userInfo']) ? "" : "hide-p";
  $unlogined = $logined == "hide-p" ? "" : "hide-p";
</php>
<p id="unlogined-p" class="{$unlogined}">
Copy after login

Reference position three in the template: Used in template tag , such as used in condition, without adding {}.

<if condition="$type neq 4">
  <p class="form-group">
    <label for="" class="control-label col-sm-3">一级部门: <span class="text-danger">*</span></label>
    <p class="col-sm-9">
      <select name="depart1_id" id="depart1_id" onchange="depart1change()" class="form-control input-sm">
        <option value="-1">-----请选择一级部门-----</option>
        <foreach name="depart1" item="vo">
          <option value="{$vo.id}">{$vo.name}</option>
        </foreach>
      </select>
    </p>
  </p>
  <p class="form-group">
    <label for="" class="control-label col-sm-3">二级部门: <span class="text-danger">*</span></label>
    <p class="col-sm-9">
      <select name="depart2_id" id="depart2_id" onchange="depart2change()" class="form-control input-sm">
        <option selected='selected'>-----请先选择一级部门-----</option>
      </select>
    </p>
  </p>
  <p class="form-group">
    <label for="" class="control-label col-sm-3">三级部门: <span class="text-danger">*</span></label>
    <p class="col-sm-9">
      <select name="depart3_id" id="depart3_id" class="form-control input-sm">
        <option selected='selected'>-----请先选择二级部门-----</option>
      </select>
    </p>
  </p>
</if>
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Analysis of high-concurrency processing operation steps of PHP reading and writing files

PHP memory release and garbage collection use Detailed explanation

The above is the detailed content of Detailed explanation of steps to display thinkPHP controller variables in templates. 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 Article Tags

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)

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles