Detailed explanation of steps to display thinkPHP controller variables in templates

php中世界最好的语言
Release: 2023-03-26 10:54:01
Original
1602 people have browsed it

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[&#39;userInfo&#39;]) ? "" : "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=&#39;selected&#39;>-----请先选择一级部门-----</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=&#39;selected&#39;>-----请先选择二级部门-----</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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!