thinkphp 分组、页面跳转与ajax
本节课大纲:
一、多应用配置技巧
二、使用分组
三、页面跳转
$this->success('查询成功',U('User/test'));
$this->redirect('User/test','',5,'页面正在跳');
四、Ajax技巧 前后台公用公共配置文件: $ pwd
/cygdrive/c/wamp/www/thinkphp5/Admin/Conf Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5/Admin/Conf
$ ls
config.php Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5/Admin/Conf
$ cat config.php
<?php
$arr=include './config.php'; $arr2=array( );
return array_merge($arr,$arr2); ?> // 当前目录下的config.php,这个当前是指主入口的路径: $arr=include './config.php'; 公用配置文件:
$ pwd
/cygdrive/c/wamp/www/thinkphp5 Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5
$ ls -ltr config.php
-rwxrwx---+ 1 Administrators None 393 五月 9 13:14 config.php Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5
$ cat config.php
<?php
return array(
//'配置项'=>'配置值'
'TMPL_L_DELIM'=>'<{', //配置左定界符
'TMPL_R_DELIM'=>'}>', //配置右定界符
'DB_PREFIX'=>'', //设置表前缀
'DB_DSN'=>'mysql://root:1234567@192.168.32.79:3306/devops', //DSN方式配置数据库信息
'SHOW_PAGE_TRACE'=>true,//开启页面Trace
/* 'URL_ROUTER_ON'=>true,
'URL_ROUTE_RULES'=>array(
':id/:num'=>'Index/index',
), */
);
?>
Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5 thinkphp 分组机制: <?php
//1.确定应用名称 Home define('APP_NAME','App'); //2. 确定应用路径 ./Home 当前目录 index.php的当前目录 前台文件夹 define('APP_PATH','./App/');
//开启调试模式 define('APP_DEBUG',true);
//4.引入核心文件 include 引入的东西错误 代码继续运行 require 出错立即结束 require './ThinkPHP/ThinkPHP.php'; ?> 'APP_GROUP_LIST' => 'Home,Admin', //项目分组设定
'DEFAULT_GROUP' => 'Home', //默认分组 在同一个应用下,再分不同的应用: $ pwd
/cygdrive/c/wamp/www/thinkphp6/App/Lib/Action Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp6/App/Lib/Action
$ ls
Admin Home IndexAction.class.php 整个应用叫app应用: <?php
//1.确定应用名称 Home define('APP_NAME','App'); //2. 确定应用路径 ./Home 当前目录 index.php的当前目录 前台文件夹 define('APP_PATH','./App/');
//开启调试模式 define('APP_DEBUG',true);
//4.引入核心文件 include 引入的东西错误 代码继续运行 require 出错立即结束 require './ThinkPHP/ThinkPHP.php'; ?> 推荐使用分应用的方式,而不是分组 分应用情况下的访问方式,多应用配置技巧: $ pwd
/cygdrive/c/wamp/www/thinkphp5 Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5
$ ls
Admin admin.php config.php Home index.php ThinkPHP Home前台应用文件夹: Admin后台应用文件夹: http://localhost/thinkphp5/admin.php http://localhost/thinkphp5/index.php //页面跳转: <?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
echo "come in Home!";
$user=M('user');
$arr=$user->select();
dump($arr);
//分配给前台,表示为list
$this->assign('list','$arr');
$this->display();
}
} 前端页面:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body> <table border='1' width='500'>
<foreach name='list' item='vo'> <tr><td><{$vo.username}></td></tr> </foreach> </table>
</body>
</html> //超链接: <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body> <table border='1' width='500'>
<foreach name='list' item='vo'> <tr><td><a href="__URL__/info?id=<{$vo.id}>"><{$vo.username}></a></td></tr> </foreach> </table>
</body>
</html> <?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
echo "come in Home!";
$user=M('user');
$arr=$user->select();
dump($arr);
//分配给前台,表示为list
$this->assign('list',$arr);
$this->display();
} public function info(){
$id=$_GET['id'];
$user=M('user');
$arr=$user->find($id);
dump($arr);
if ($arr){
$this->success('index');
}
else {
//失败后自动跳转到上一页
$this->error('查询失败');
}
$this->assign('list',$arr);
$this->display();
}
} //redirect 跳转: <?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
echo "come in Home!";
$user=M('user');
$arr=$user->select();
dump($arr);
//分配给前台,表示为list
$this->assign('list',$arr);
$this->display();
} public function info(){
$id=$_GET['id'];
$user=M('user');
$arr=$user->find(100);
dump($arr);
if ($arr){
$this->success('index');
}
else {
//失败后自动跳转到上一页
$this->redirect('User/index');
}
$this->assign('list',$arr);
$this->display();
}
} 跳转到:
http://localhost/thinkphp5/index.php/User/index User/index 页面 Ajax 技巧: 在框架里面,脚本都是被方法所取代 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script src="__PUBLIC__/Js/jquery.js"></script>
<script>
$(function(){
$('button').bind('click',function(){ $.get('__URL__/getAjax',function(jdata){
<!--alert (JSON.stringify(data));-->
if (jdata.status==1){
alert(jdata.data);
}
});
}); }); </script>
</head>
<body>
<div style='height:50px;background:yellow' id='did'></div>
<button>点击</button>
<script>
document.write(new Date());
</script>
</body>
</html> <?php
class IndexAction extends Action { public function index(){
$this->display();
} public function getAjax(){
//echo 'aaaaaaa';
$this->ajaxReturn('这里是数据','信息1',1);
} }
thinkphp 分组、页面跳转与ajax的更多相关文章
- ThinkPHP页面跳转、Ajax技巧详细介绍(十八)
原文:ThinkPHP页面跳转.Ajax技巧详细介绍(十八) ThinkPHP页面跳转.Ajax技巧详细介绍 一.页面跳转 $this->success('查询成功',U('User/test' ...
- 【转】ThinkPHP 页面跳转
ThinkPHP 提供了success 与error 方法用于带提示信息的页面跳转,如添加数据后显示提示信息并跳转等.success 方法用于操作成功后的提示,error 用于操作失败后的提示,二者使 ...
- ThinkPHP 分组,应用,跳转
一.多应用配置技巧 在主入口文件index.php同级目录,新建一个 config.php 写入公共的配置项,然后在前后台各自的配置文件config.php中 $arr = include ...
- Ajax发送POST请求SpringMVC页面跳转失败
问题描述:因为使用的是SpringMVC框架,所以想使用ModelAndView进行页面跳转.思路是发送POST请求,然后controller层中直接返回相应ModelAndView,但是这种方法不可 ...
- 通过配置http拦截器,来进行ajax请求验证用户登录的页面跳转
在.NET中验证用户是否登录或者是否过期,若需要登录时则将请求转向至登录页面. 这个流程在进行页面请求时是没问题的,能正确进行页面跳转. 然而在使用xmlhttprequest时,或者jq的getJs ...
- 爱上MVC~ajax调用分部视图session超时页面跳转问题
回到目录 这个问题出现了很多年了,都没有解决,问题是这样的,有一个需要授权才可以访问的分部视图,在一个view中使用ajax的方法去调用它,然后更新页面的局部DIV,这时,如果你长时间不操作,sess ...
- js页面用定时任务通过AJAX获取后台数据,但是从这个页面跳转到其他页面后,定时任务仍然在定时请求后台
setInterval(function(){//ajax 请求后台数据},1000);这个是A页面的定时器然后我在A页面通过其他请求跳转到其他页面之后后台发现A页面的定时器的那个请求仍然在执行为什么 ...
- ajax 提交成功页面跳转问题
jsx/ajax提交成功后采用以下方式跳转:1.本页面跳转:"window.location.href"."location.href" 2.上一层页面跳转:& ...
- ajax 如何实现页面跳转
老师,您好.jquery的ajax如何实现页面跳转?例如:登陆页面属于用户名和密码后,点击登陆,验证用户名和密码,正确后,跳转到其他页面.能否给个例子. 下面列了五个例子来详细说明,这几个例子的主要功 ...
随机推荐
- 从事web前端两年半后的迷茫
做了两年半的重构,突然有种迷茫的感觉,好像瓶颈了,不知道自己该怎么继续走下去,以前刚毕业的时候,总觉得自己有好多的东西要学在前端方面,所以有那个促使自己去学习的动力,每当没工作任务的时候,自己总是去主 ...
- Pascal向C++的跨越
最近从pas转向了C++,觉得需要在语言上总结对比一下,以及记录一些注意点,关于STL,还需要之后好好地学习.同时,希望这篇文章对从pas转C++的同学有所帮助. 基本类型 首先是基本类型的比较: P ...
- php:根据中文裁减字符串函数方法
define(CHARSET, 'UTF-8'); // 系统默认编码 /** * 根据中文裁减字符串 * @param $string - 字符串 * @param $length - 长度 * @ ...
- 谁动了我的CurrentPrincipal?解释一下为什么CurrentPrincipal变了,并解决这个问题。
在上一篇博客中我遇到了一个问题,并且导致了我无法继续进行授权和验证.经过查阅资料和解决另外一个问题的过程,我突然想通了为什么CurrentPrincipal变了.并且经过验证后的确是我所理解的那样.下 ...
- Chrome插件Visual Event查看Dom元素绑定事件的利器
找这工具找了好久,统一找着了,开发人员不可多得的好东东,收藏做一下分享. 用Chrome插件Visual Event查看Dom绑定的事件 Visual Event简介 Visual Event是一个开 ...
- Jquery调用webService的四种方法 转载-记录
我总结几个关键点 1. 服务必须声明为ScriptService(否则会出现下面的问题) 2.服务的方法不需要任何更改,保持原状 3.客户端用jquery的.ajax方法来调用 3.1 type必须是 ...
- HDU 2023题解分析
我想说这道题我还没弄明白我错哪了,交了20多遍一直都是Runtime Error,改了N次还是不对,后来搜了一下,说是数组开小了,又把数组开大,还不对,又改发现一个平均值求错,再改,还不对,洗洗睡吧. ...
- Python之美[从菜鸟到高手]--urlparse源码分析
urlparse是用来解析url格式的,url格式如下:protocol :// hostname[:port] / path / [;parameters][?query]#fragment,其中; ...
- 《JavaScript权威指南》拾遗(下)
一.类和原型 1.在JavaScript中,类的实现是基于原型继承机制的,如果两个实例都是从同一个原型对象中继承了属性,则它们是同一个类的实例. 2.原型对象是类的唯一 ...
- Oracle Split 函数
为了让 PL/SQL 函数返回数据的多个行,必须通过返回一个 REF CURSOR 或一个数据集合来完成.REF CURSOR 的这种情况局限于可以从查询中选择的数据,而整个集合在可以返回前,必须进行 ...