thinkphp 分组、页面跳转与ajax
来源:互联网 发布:lol网吧代理软件 编辑:程序博客网 时间:2024/05/01 04:47
本节课大纲:一、多应用配置技巧二、使用分组三、页面跳转$this->success('查询成功',U('User/test'));$this->redirect('User/test','',5,'页面正在跳');四、Ajax技巧前后台公用公共配置文件:$ pwd/cygdrive/c/wamp/www/thinkphp5/Admin/ConfAdministrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5/Admin/Conf$ lsconfig.phpAdministrator@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/thinkphp5Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5$ ls -ltr config.php-rwxrwx---+ 1 Administrators None 393 五月 9 13:14 config.phpAdministrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5$ cat config.php<?phpreturn 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/thinkphp5thinkphp 分组机制:<?php//1.确定应用名称 Homedefine('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/ActionAdministrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp6/App/Lib/Action$ lsAdmin Home IndexAction.class.php整个应用叫app应用:<?php//1.确定应用名称 Homedefine('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/thinkphp5Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp5$ lsAdmin admin.php config.php Home index.php ThinkPHPHome前台应用文件夹:Admin后台应用文件夹:http://localhost/thinkphp5/admin.phphttp://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/indexUser/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><?phpclass IndexAction extends Action {public function index(){$this->display();}public function getAjax(){//echo 'aaaaaaa';$this->ajaxReturn('这里是数据','信息1',1);}}
0 0
- thinkphp 分组、页面跳转与ajax
- 分组、页面跳转与ajax
- ThinkPHP页面跳转success与error方法
- ThinkPHP页面跳转、Ajax技巧详细介绍(十八)
- thinkphp使用ajax提交后怎么做页面跳转
- thinkphp 页面跳转不显示问题 data-ajax="false"
- Thinkphp中页面的跳转
- thinkphp 页面跳转传递参数
- Thinkphp页面跳转设置跳转等待时间
- ajax页面实现跳转
- AJAX跳转页面
- ajax执行页面跳转
- ThinkPHP 页面请求和AJAX
- thinkphp与ajax传值
- Ajax,jQuery实现页面无跳转与对比
- jqueryMobile页面跳转ajax载入与缓存问题
- ajax如何实现页面局部跳转与结果返回
- thinkPHP底层设置跳转404页面
- 两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
- 【Windows】【Runtime Error】Explorer.exe异常
- 第8章:structures, unions, and enumerations
- 待后续了解
- 数据分析/数据挖掘/机器学习---- 必读书目
- thinkphp 分组、页面跳转与ajax
- 深圳8千名滴滴司机被封号? 官方:只是平台整治
- 学会自己测天气系列八卦基础 01
- POJ 2585 Window Pains (窗口绘制)(拓扑排序)
- caffe如何将图片数据写成lmdb格式
- table跨行跨列,字体大小
- 一次失败的刷题经历:[LeetCode]292之尼姆游戏(Nim Game)
- resource: *********.hbm.xml not found 这个错误完美解决
- 文件上传