THINKPHP21_22/23_24/25

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/usr/local/apache-2.4/conf/extra   httpd.conf # # ThinkPHP 3.1.2 控制器的模块和操作 # 讲师:赵桐正 微博:http://weibo.com/zhaotongzheng 本节课大纲: //可以查看咱们的   thinkphp3 一、空模块和空操作 1、空操作//空方法! function \_empty($name){ $this->show("$name 不存在 <a href='\_\_APP__/Index/index'>返回首页</a>"); } 2.空模块 class EmptyAction extends Action{ function index(){ $m =  M('City'); $arr = $m ->select(); $this -> assign( 'list',$arr ); $name =  MODULE\_NAME;//可以去查看常量参考!thinkphp手册!20附录里面! $this ->  display("City:$name") ;  //e1   用的双引号!只是单纯的访问下,不进入  方法操作! } } 二、前置操作和后置操作 1、前置操作: \_before_操作名 2、后置操作: \_after\_操作名

* * *

23--24   开发手册    3.1.2   注意  5.控制器当就有!!! # # ThinkPHP 3.1.2 URL # 讲师:赵桐正 微博:http://weibo.com/zhaotongzheng 本节课大纲: 一、URL规则 1、默认是区分大小写的 2、如果我们不想区分大小写可以改配置文件 'URL\_CASE\_INSENSITIVE'=>true,//url不区分大小写 3、如果模块名为 UserGroupAction 那么url找模块就必要要写成 http://localhost/thinkphp4/index.php/user_group/index 4、如果'URL\_CASE\_INSENSITIVE'=>false 那么url也可以写为 http://localhost/thinkphp4/index.php/UserGroup/index 二、URL伪静态 URL伪静态// <!\[CDATA\[ $(function(){ $(window).resize(function(){ $('.book-content').css('min-height', $(window).height() - 130); }).resize(); //表格隔行变色 $('table').TableColor(); //代码高亮 prettyPrint(); }); //表格隔行变色插件 $.fn.TableColor = function(){ return $(this).each(function(){ if(this.nodeName.toLowerCase() != 'table') return; var self = $(this); self.find('tr').each(function(index) { var \_this = $(this); if(index % 2 == 0){ \_this.addClass('add'); } else { \_this.addClass('even'); } \_this.hover( function(){\_this.addClass('hover')}, function(){\_this.removeClass('hover')} ); }); }); } // \]\]>

ThinkPHP支持伪静态URL设置,可以通过设置URL\_HTML\_SUFFIX参数随意在URL的最后增加你想要的静态后缀,而不会影响当前操作的正常执行。例如,我们设置

1. 'URL\_HTML\_SUFFIX'=>'shtml'

的话,我们可以把下面的URL

1. http://serverName/Blog/read/id/1

变成

1. http://serverName/Blog/read/id/1.shtml

后者更具有静态页面的URL特征,但是具有和前面的URL相同的执行效果,并且不会影响原来参数的使用。 注意:伪静态后缀设置时可以不包含后缀中的“.”。

URL伪静态// <!\[CDATA\[ $(function(){ $(window).resize(function(){ $('.book-content').css('min-height', $(window).height() - 130); }).resize(); //表格隔行变色 $('table').TableColor(); //代码高亮 prettyPrint(); }); //表格隔行变色插件 $.fn.TableColor = function(){ return $(this).each(function(){ if(this.nodeName.toLowerCase() != 'table') return; var self = $(this); self.find('tr').each(function(index) { var \_this = $(this); if(index % 2 == 0){ \_this.addClass('add'); } else { \_this.addClass('even'); } \_this.hover( function(){\_this.addClass('hover')}, function(){\_this.removeClass('hover')} ); }); }); } // \]\]>

3.1版本开始,默认情况下,可以支持所有的静态后缀,并且会记录当前的伪静态后缀到常量\_\_EXT\_\_,但不会影响正常的页面访问。

所以要想限制的话就要: 'URL\_HTML\_SUFFIX'=>'html|shtml|xml',//限制伪静态的后缀 三、URL路由(注意必须是pathinfo模式的,而且按照下面的开启路由支持!) 1、启动路由 要在配置文件中开启路由支持 2、使用路由 1.规则表达式配置路由 'my'=>'Index/index',//静态地址路由 ':id/:num'=>'Index/index',//动态地址路由 'year/:year/:month/:date'=>'Index/index',//动态和静态混合地址路由 'year/:year\\d/:month\\d/:date\\d'=>'Index/index',//动态和静态混合地址路由 加上 \\d代表类型只能是数字 'my/:id$'=>'Index/index',// 加上$说明地址中只能是 my/1000 后面不能有其他内容了 2.正则表达式配置路由 '/^year\\/(\\d{4})\\/(\\d{2})\\/(\\d{2})/'=>'Index/index?year=:1&month=:2&date=:3' 3、注意事项: 1.越复杂的路由越往前面放 'URL\_ROUTE\_RULES'=>array( 'my/:year/:month:/:day'=>'Index/day', 'my/:id\\d'=>'Index/index', 'my/:name'=>'Index/index', ) 2.可以使用$作为完全匹配的路由规则 'URL\_ROUTE\_RULES'=>array( 'my/:id\\d$'=>'Index/index', 'my/:name$'=>'Index/index', 'my/:year/:month:/:day$'=>'Index/day', ), 3.用正则匹配的方式 'URL\_ROUTE\_RULES'=>array( '/^my\\/(\\d+)$/'=>'Index/index?id=:1', '/^my\\/(\\w+)$/'=>'Index/index?name=:1', '/^my\\/(\\d{4})\\/(\\d{2})\\/(\\d{2})$/'=>'Index/day?year=:1&month=:2&day=:3', ), 四、URL重写 URL重写// <!\[CDATA\[ $(function(){ $(window).resize(function(){ $('.book-content').css('min-height', $(window).height() - 130); }).resize(); //表格隔行变色 $('table').TableColor(); //代码高亮 prettyPrint(); }); //表格隔行变色插件 $.fn.TableColor = function(){ return $(this).each(function(){ if(this.nodeName.toLowerCase() != 'table') return; var self = $(this); self.find('tr').each(function(index) { var \_this = $(this); if(index % 2 == 0){ \_this.addClass('add'); } else { \_this.addClass('even'); } \_this.hover( function(){\_this.addClass('hover')}, function(){\_this.removeClass('hover')} ); }); }); } // \]\]>

通常的URL里面含有index.php,为了达到更好的SEO效果可能需要去掉URL里面的index.php ,通过URL重写的方式可以达到这种效果,通常需要服务器开启URL\_REWRITE模块才能支持。 下面是Apache的配置过程,可以参考下: 1、httpd.conf配置文件中加载了mod\_rewrite.so模块 2、AllowOverride None 将None改为 All 3、确保URL_MODEL设置为2 4、把下面的内容保存为.htaccess文件放到入口文件的同级目录下

1. <IfModulemod_rewrite.c>
2. RewriteEngine on
3. RewriteCond %{REQUEST_FILENAME} !-d
4. RewriteCond %{REQUEST_FILENAME} !-f
5. RewriteRule ^(.*)$ index.php/$1 \[QSA,PT,L\]
6. </IfModule>

五、URL生成 URL重写// <!\[CDATA\[ $(function(){ $(window).resize(function(){ $('.book-content').css('min-height', $(window).height() - 130); }).resize(); //表格隔行变色 $('table').TableColor(); //代码高亮 prettyPrint(); }); //表格隔行变色插件 $.fn.TableColor = function(){ return $(this).each(function(){ if(this.nodeName.toLowerCase() != 'table') return; var self = $(this); self.find('tr').each(function(index) { var \_this = $(this); if(index % 2 == 0){ \_this.addClass('add'); } else { \_this.addClass('even'); } \_this.hover( function(){\_this.addClass('hover')}, function(){\_this.removeClass('hover')} ); }); }); } // \]\]>

通常的URL里面含有index.php,为了达到更好的SEO效果可能需要去掉URL里面的index.php ,通过URL重写的方式可以达到这种效果,通常需要服务器开启URL\_REWRITE模块才能支持。 下面是Apache的配置过程,可以参考下: 1、httpd.conf配置文件中加载了mod\_rewrite.so模块 2、AllowOverride None 将None改为 All 3、确保URL_MODEL设置为2 4、把下面的内容保存为.htaccess文件放到入口文件的同级目录下

1. <IfModulemod_rewrite.c>
2. RewriteEngine on
3. RewriteCond %{REQUEST_FILENAME} !-d
4. RewriteCond %{REQUEST_FILENAME} !-f
5. RewriteRule ^(.*)$ index.php/$1 \[QSA,PT,L\]
6. </IfModule>

URL生成// <!\[CDATA\[ $(function(){ $(window).resize(function(){ $('.book-content').css('min-height', $(window).height() - 130); }).resize(); //表格隔行变色 $('table').TableColor(); //代码高亮 prettyPrint(); }); //表格隔行变色插件 $.fn.TableColor = function(){ return $(this).each(function(){ if(this.nodeName.toLowerCase() != 'table') return; var self = $(this); self.find('tr').each(function(index) { var \_this = $(this); if(index % 2 == 0){ \_this.addClass('add'); } else { \_this.addClass('even'); } \_this.hover( function(){\_this.addClass('hover')}, function(){\_this.removeClass('hover')} ); }); }); } // \]\]>

如果不定义项目和模块的话 就表示当前项目和模块名称,下面是一些简单的例子:

1. U('User/add') // 生成User模块的add操作的URL地址
2. U('Blog/read?id=1') // 生成Blog模块的read操作 并且id为1的URL地址
3. U('Admin/User/select') // 生成Admin分组的User模块的select操作的URL地址

具体查看-----3.1.2!!!!!!!!!!

* * *

25 # # ThinkPHP 3.1.2 URL # 讲师:赵桐正 微博:http://weibo.com/zhaotongzheng 本节课大纲: 一、多应用配置技巧 二、使用分组 5.6  模块分组 三、页面跳转 $this->success('查询成功',U('User/test')); $this->redirect('User/test','',5,'页面正在跳'); 参考手册  5.14页面跳转// <!\[CDATA\[ $(function(){ $(window).resize(function(){ $('.book-content').css('min-height', $(window).height() - 130); }).resize(); //表格隔行变色 $('table').TableColor(); //代码高亮 prettyPrint(); }); //表格隔行变色插件 $.fn.TableColor = function(){ return $(this).each(function(){ if(this.nodeName.toLowerCase() != 'table') return; var self = $(this); self.find('tr').each(function(index) { var \_this = $(this); if(index % 2 == 0){ \_this.addClass('add'); } else { \_this.addClass('even'); } \_this.hover( function(){\_this.addClass('hover')}, function(){\_this.removeClass('hover')} ); }); }); } // \]\]>

1. //默认错误跳转对应的模板文件
2. 'TMPL\_ACTION\_ERROR' => THINK_PATH . 'Tpl/dispatch_jump.tpl';
3. //默认成功跳转对应的模板文件
4. 'TMPL\_ACTION\_SUCCESS' => THINK_PATH . 'Tpl/dispatch_jump.tpl';

四、Ajax技巧   5.19AJAX返回// <!\[CDATA\[ $(function(){ $(window).resize(function(){ $('.book-content').css('min-height', $(window).height() - 130); }).resize(); //表格隔行变色 $('table').TableColor(); //代码高亮 prettyPrint(); }); //表格隔行变色插件 $.fn.TableColor = function(){ return $(this).each(function(){ if(this.nodeName.toLowerCase() != 'table') return; var self = $(this); self.find('tr').each(function(index) { var \_this = $(this); if(index % 2 == 0){ \_this.addClass('add'); } else { \_this.addClass('even'); } \_this.hover( function(){\_this.addClass('hover')}, function(){\_this.removeClass('hover')} ); }); }); } // \]\]>

1. $data\['status'\] = 1;
2. $data\['info'\] = 'info';
3. $data\['size'\] = 9;
4. $data\['url'\] = $url;
5. $this->ajaxReturn($data,'JSON');

  AJAX返回// <!\[CDATA\[ $(function(){ $(window).resize(function(){ $('.book-content').css('min-height', $(window).height() - 130); }).resize(); //表格隔行变色 $('table').TableColor(); //代码高亮 prettyPrint(); }); //表格隔行变色插件 $.fn.TableColor = function(){ return $(this).each(function(){ if(this.nodeName.toLowerCase() != 'table') return; var self = $(this); self.find('tr').each(function(index) { var \_this = $(this); if(index % 2 == 0){ \_this.addClass('add'); } else { \_this.addClass('even'); } \_this.hover( function(){\_this.addClass('hover')}, function(){\_this.removeClass('hover')} ); }); }); } // \]\]>

1. $data\['status'\] = 1;
2. $data\['info'\] = 'info';
3. $data\['size'\] = 9;
4. $data\['url'\] = $url;
5. $this->ajaxReturn($data,'JSON');
(っ•̀ω•́)っ✎⁾⁾ 坚持技术学习、内容输出与分享,您的支持将鼓励我继续创作!(*/ω\*)
( • ̀ω•́ )✧如有疑问或需要技术讨论,请留言或发邮件到 aclearzhang@qq.com.(*・ω< ) 
  • 本文作者:: AClearZhang
  • 本文链接:: 320.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!