这是一个过滤URL中 多个’/'的例子
修改 apps/myapp/config/filters.yml
添加代码
myFilter:
class: myFilter
(myFilter可自定义)
创建文件myFilter.class.php
创建位置apps/myapp/lib/
文件内容如下
使用preg_match 是因为 ereg 过时
注意preg_match 匹配正则时以’/'开始和结束
class myFilter extends sfFilter
{
public function execute ($filterChain)
{
//提取uri
$str = $_SERVER['REQUEST_URI'];
//判断是否匹配正则
if(preg_match("/(.*\/{2,}.*)((\.html)*)/",$str)){
//要跳转的页面
header("Location:/error.html");
//跳转后代码不执行
exit();
}
//执行下一个filter
$filterChain->execute();
}
}
修改apps/myapp/config/routing.yml
添加代码 此代码用来定义URL /error.html 要执行的模块和动作
Error:
url: /error.html
param: { module: index, action: error404}
2010-05-26
使用SYMFONY Filter 过滤URL
1 条评论 »
这篇文章上的评论 RSS feed TrackBack URL

blog的几位联合作者有没有在上海的?
我有个symfony的项目需要兼职人员协作开发. 请帮忙询问一下.
qq: 511976947
Comment 由 littlexiang — 2010-07-11 @ 01:35