ThinkPHP常用
thinkphp视图页面调用函数:
{:getUserNameByUserId(
$vo[
'create_user_id'])}
视图页面调用时间函数(时间戳转换为时间):
{:date(
'Y-m-d H:i:s',
$vo[
'create_time'])}
下拉菜单修改:
控制器:
$selected=
"";
if(
$vo[
'sex']==
"女")
$selected=
"selected";
$this->assign(
"selected",
$selected);
视图:
<select name=
"sex">
<option value=
"男">男</option>
<option value=
"女" {
$selected}>女</option>
</select>
下拉菜单修改数据库读取:
控制器:
$type = M(
'yuanxi');
$arr =
$type->select();
$this->assign(
'yuanxi',
$arr);
$vo=
$form->where(
$where)->find(); //第二种方法
$this->assign(
'vo',
$vo);
视图:
<select name=
"yuanxi_id">
<option value=
"">--选择所属院系--</option>
<volist name=
"yuanxi" id=
"v">
<option value=
"{$v.yuanxi_id}"<
if condition=
"$v.yuanxi_id eq $vo['yuanxi_id']"> selected</
if>>{
$v.yuanxi_name} ({
$v.yuanxi_id})</option>
</volist>
</select>
ThinkPHP JS U方法传参数:
window.location.href =
"{:U('Admin/APP/edit_app')}/id/"+sysId;
//window.location.href =
"edit_app?id="+sysId;//默认为当前控制器
回车时提交数据(回车按键编号为
13):
$(this).keydown(function (event) {
if (event.keyCode ==
13) {
login();
}
});
<a href=
"{:U($vo['url'])}" class=
"btn btn-default">{
$vo.name}</a>
查找树的孩子的数量
function findChild(
$arr){
static
$tree = array(); //static为静态的,其值可以累加
foreach (
$arr as
$key=>
$val){
$tree[] =
$val;
if (count(
$val[
'_data']) >
0){
findChild(
$val[
'_data']);
}
}
return $tree;
}
date(
"Y-m-d H:i:s", time());
MySQL递归查询树的所有节点:
SELECT
id
FROM
(
SELECT
t1.id,
IF (
find_
in_
set(spreader_uid, @pids) >
0,
@pids := concat(@pids,
',', id),
0
) AS ischild
FROM
(
SELECT
id,
spreader_uid
FROM
users t
ORDER BY
spreader_uid,
id
) t1,
(SELECT @pids :=
104) t2
) t3
WHERE
ischild !=
0
创建树
protected function treeData(
$data,
$pid =
0){
$result = array();
foreach(
$data as
$v){
if(
$v[
'pid'] ==
$pid){
$v[
'children'] =
$this->treeData(
$data,
$v[
'id']);
$result[] =
$v;
}
}
return $result;
}