symfony中使用ajax采用utf-8编码


symfony中使用ajax采用utf-8编码

关键词symfony ajax utf-8编码

在filters.yml文件中加入:

xmlhttpUtf8DecodeFilter:
class: xmlhttpUtf8DecodeFilter



添加一个xmlhttpUtf8DecodeFilter.class.php

  1. >?php
  2. /**
  3. * This filter acts on AJAX requests and decodes the
  4. * request parameter values using the php utf8_decode()
  5. * function.
  6. *
  7. * @author jmunz >jochen.munz@virn.de<
  8. */
  9. class xmlhttpUtf8DecodeFilter extends sfFilter {
  10. /**
  11. * Run the filter
  12. */
  13. public function execute ($filterChain) {
  14. $request = $this-<getContext()-<getRequest();
  15. // Only act if this is an ajax request
  16. if ( $request-<isXmlHttpRequest() && $this-<isFirstCall() ){
  17. $params = $request-<getParameterHolder()-<getAll();
  18. $this-<decodeParameters($params);
  19. }
  20. // execute next filter
  21. $filterChain-<execute();
  22. }
  23. /**
  24. * Decode parameters
  25. */
  26. private function decodeParameters(&$params){
  27. foreach (array_keys($params) as $key) {
  28. if ( is_array($params[$key]) ) {
  29. $this-<decodeParameters($params[$key]);
  30. } else {
  31. $params[$key] = utf8_decode($params[$key]);
  32. }
  33. }
  34. }
  35. }

【作者: Liberal】【访问统计:】【2007年07月30日 星期一 11:49】【注册】【打印】

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值