您当前的位置: 首页 > 学无止境 > 网站建设 网站首页网站建设
thinkphp分组、页面跳转、ajax
发布时间:2016-01-03 10:46:17编辑:雪饮阅读()
复制index入口文件为副本,建立admin应用及目录
在项目目录下建立公共配置文件(无论前台或者后台):
前台或者后台独立配置文件中引入公共配置文件并合并返回公共配置文件与自身配置文件所返回的两个数组:
$arr=include './config.php';
$arr2=array(
//'配置项'=>'配置值'
);
return array_merge($arr,$arr2);
合并前后台应用:
配置文件中配置合并前后台的参数:
模块目录中建立home和admin文件夹并将index模块分别复制进去
访问前台或后台:
跳转:
public function info(){
$id=$_GET["id"];
$m=M("User");
$arr=$m->find($id);
$this->assign("list",$arr);
$this->display();
}
模块中建立info方法:
public function info(){
$id=$_GET["id"];
$m=M("User");
$arr=$m->find($id);
if($arr){
$this->assign("list",$arr);
$this->display();
}
else{
$this->error("查询失败");
}
}
ThinkPHP find() 方法是和 select() 用法类似的一个方法,不同之处 find() 查询出来的始终只有一条数据,即系统自动加上了 LIMIT 1 限制。
当确认查询的数据记录只能是一条记录时,建议使用 find() 方法查询,如用户登录账号检测:
建立info详情页模版:
跳转到其它模块:
public function info(){
$id=$_GET["id"];
$m=M("User");
$arr=$m->find($id);
if($arr){
$this->assign("list",$arr);
$this->display();
}
else{
$this->success("成功",U("User/test"));
}
}
直接跳转:
public function info(){
$id=$_GET["id"];
$m=M("User");
$arr=$m->find($id);
if($arr){
$this->assign("list",$arr);
$this->display();
}
else{
$this->redirect("User/test","",3,"3秒后准备跳转");
}
}
Ajax:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
<script type="text/javascript">
$(function(){
$('button').bind('click',function(){
$.get('__URL__/getajax',function(data){
alert(data);
});
});
});
</script>
</head>
<body>
<button>ajax</button>
</body>
</html>
Index模块中建立getajax方法:
以json方式弹出后台获取信息:
alert(JSON.stringify(data));
取出json中指定字段信息:
if(data.status==1){
alert(data.data);
}
将取得的json数据给指定div中:
if(data.status==1){
$("div").html(data.data);
}
}
关键字词:thinkphp,分组,ajax,个人博客