这篇文章主要介绍了thinkPHP控制器变量在模板中的显示方法,结合实例形式简单分析了thinkPHP控制器变量在模板中的三种常见的显示操作实现技巧,需要的朋友可以参考下
本文实例讲述了thinkPHP控制器变量在模板中的显示方法。分享给大家供大家参考,具体如下:
控制器中变量
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();
}
模板中引用位置一:php代码中,直接用$i;
<php>
echo $i;
</php
模板中引用位置二:模板中直接应用{$i}
或者 class="{$unlogined}"
<font color="red">注意:1.非相关人员,严禁注册。{$i}</font><br>
<php>
$logined = is_array($_SESSION['userInfo']) ? "" : "hide-div";
$unlogined = $logined == "hide-div" ? "" : "hide-div";
</php>
<div id="unlogined-div" class="{$unlogined}">
模板中引用位置三:模板标签中用,如condition中用,不加{}。
<if condition="$type neq 4">
<div class="form-group">
<label for="" class="control-label col-sm-3">一级部门: <span class="text-danger">*</span></label>
<div 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>
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-sm-3">二级部门: <span class="text-danger">*</span></label>
<div class="col-sm-9">
<select name="depart2_id" id="depart2_id" onchange="depart2change()" class="form-control input-sm">
<option selected='selected'>-----请先选择一级部门-----</option>
</select>
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-sm-3">三级部门: <span class="text-danger">*</span></label>
<div class="col-sm-9">
<select name="depart3_id" id="depart3_id" class="form-control input-sm">
<option selected='selected'>-----请先选择二级部门-----</option>
</select>
</div>
</div>
</if>
更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》及《PHP模板技术总结》。
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
织梦狗教程
本文标题为:thinkPHP控制器变量在模板中的显示方法示例


基础教程推荐
猜你喜欢
- PHP实现创建一个RPC服务操作示例 2023-04-01
- PHP使用SMTP邮件服务器发送邮件示例 2022-11-16
- thinkPHP3.2.2框架行为扩展及demo示例 2022-11-07
- PHP数据加密方式梳理介绍 2023-07-03
- TP5(thinkPHP5框架)基于bootstrap实现的单图上传插件用法示例 2023-01-19
- php中使用array_filter()函数过滤数组实例讲解 2023-05-19
- PHP实现生成数据字典功能示例 2022-10-18
- PHP删除数组中指定值的元素常用方法实例分析【4种方法】 2022-11-12
- laravel model模型定义实现开启自动管理时间created_at,updated_at 2023-03-02
- TP5 连接多个数据库及使用方法 2023-08-30