Home >Backend Development >PHP Tutorial >Detailed explanation of steps to display thinkPHP controller variables in templates
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(); }
Reference position one in the template: In the php code, use $i;
directly
<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['userInfo']) ? "" : "hide-p"; $unlogined = $logined == "hide-p" ? "" : "hide-p"; </php> <p id="unlogined-p" class="{$unlogined}">
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>
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!