Home>Article>Backend Development> 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 theprecautionsfor 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
echo $i; Reference position two in the template:Apply directly in the template
{$i}
orclass="{$unlogined}"
注意:1.非相关人员,严禁注册。{$i}
$logined = is_array($_SESSION['userInfo']) ? "" : "hide-p"; $unlogined = $logined == "hide-p" ? "" : "hide-p"; Reference position three in the template:Used in template tag, such as used in condition, without adding {}.
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!