symfony中使用ajax采用utf-8编码
关键词: symfony ajax utf-8编码在filters.yml文件中加入:
xmlhttpUtf8DecodeFilter:
class: xmlhttpUtf8DecodeFilter
添加一个xmlhttpUtf8DecodeFilter.class.php
- >?php
- /**
- * This filter acts on AJAX requests and decodes the
- * request parameter values using the php utf8_decode()
- * function.
- *
- * @author jmunz >jochen.munz@virn.de<
- */
- class xmlhttpUtf8DecodeFilter extends sfFilter {
- /**
- * Run the filter
- */
- public function execute ($filterChain) {
- $request = $this-<getContext()-<getRequest();
- // Only act if this is an ajax request
- if ( $request-<isXmlHttpRequest() && $this-<isFirstCall() ){
- $params = $request-<getParameterHolder()-<getAll();
- $this-<decodeParameters($params);
- }
- // execute next filter
- $filterChain-<execute();
- }
- /**
- * Decode parameters
- */
- private function decodeParameters(&$params){
- foreach (array_keys($params) as $key) {
- if ( is_array($params[$key]) ) {
- $this-<decodeParameters($params[$key]);
- } else {
- $params[$key] = utf8_decode($params[$key]);
- }
- }
- }
- }
【作者: Liberal】【访问统计:】【2007年07月30日 星期一 11:49】【注册】【打印】
4896

被折叠的 条评论
为什么被折叠?



