2017-04-27 16:26:25 4369次浏览 3条回答 0 悬赏 10 金钱

yii2如何对全局post进行trim,类似于thinkphp里的 'DEFAULT_FILTER' => 'htmlspecialchars', // 默认参数过滤方法 用于I函数...

  • 回答于 2017-04-27 16:35 举报

    没发现这样的东西,估计的自己写

  • 回答于 2017-04-27 17:13 举报

    重写Request的Post方法
    在这两边遍历trim就可以了

    /**
    * Returns POST parameter with a given name. If name isn't specified, returns an array of all POST parameters.
    *
    * @param string $name the parameter name
    * @param mixed $defaultValue the default parameter value if the parameter does not exist.
    * @return array|mixed
    */
    public function post($name = null, $defaultValue = null)
    {
        if ($name === null) {
            return $this->getBodyParams();
        } else {
            return $this->getBodyParam($name, $defaultValue);
        }
    }
    
    1 条回复
    回复于 2017-05-06 18:15 回复

    此方法我试了一下,不行,我需要的是在入库yuan证的时候,就会在前端提醒,也就是走的模型中的rules,在rules中加trim后,前端是可以自动过滤掉的

  • 回答于 2017-04-27 17:53 举报

    赞同楼上说的,但是不建议直接改源码,可以写一个类继承系统的Request类,然后在配置文件里,配置上你自己的Request类
    'request' => ['class' => 'xx\xx\YourRequest'],

    , 觉得很赞
您需要登录后才可以回答。登录 | 立即注册
小程府
经理

小程府 北京

注册时间:2016-03-23
最后登录:2021-02-09
在线时长:30小时31分
  • 粉丝13
  • 金钱255
  • 威望100
  • 积分1555

热门问题