Home  >  Article  >  Backend Development  >  How to display variables in thinkPHP controller in templates

How to display variables in thinkPHP controller in templates

小云云
小云云Original
2018-03-28 10:02:191419browse

This article mainly introduces the display method of thinkPHP controller variables in templates, and briefly analyzes three common display operation implementation techniques of thinkPHP controller variables in templates in the form of examples. Friends in need can refer to it. Hope it helps everyone.

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();
}

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


##

<php>
  echo $i;
</php

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}">

Reference position three in the template:

Used in template tags, 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>

Related recommendations:

A brief analysis of thinkphp controller

# #

The above is the detailed content of How to display variables in thinkPHP controller in templates. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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