【问题标题】:yii2 model str_replace() for all attributes所有属性的 yii2 模型 str_replace()
【发布时间】:2015-07-29 13:47:32
【问题描述】:

hello 's 在数据库中保存为hello \'s

$eventDetail = Event::find()
                ->joinWith('eventQuestion', true)
                ->joinWith('eventQuestion.questionOption', true)
                ->where(['=','event.id',$id])
                ->one();

所有包含\'的数据都应替换为'

我应该在模型中进行哪些更改来处理这个问题?

【问题讨论】:

    标签: php yii2


    【解决方案1】:

    我愿意

    public function retrieveById() {
    $eventDetail = Event::find()
                    ->joinWith('eventQuestion', true)
                    ->joinWith('eventQuestion.questionOption', true)
                    ->where(['event.id' =>$id])
                    ->one();
    
    // this or do a for loop if you want to loop through $eventDetail
    $eventDetail->description = str_replace("\'","'", $eventDetail->description);
    }
    

    【讨论】:

      【解决方案2】:

      在 Yii2 中,如果我们添加任何带有单引号的值,默认情况下它会添加不带反斜杠的值,就像您希望在视图页面中显示的那样。

      您是在保存之前使用反斜杠转换单引号还是隐式更改?

      如果它隐式更改,您可以检查 PHP.ini 中的 magic_quote_gpc 设置。它应该关闭。如果您的 php 版本低于 5.4,那么您应该更改 magic_quote 设置。如果您的 PHP 版本 > 5.4,那么应该还有其他一些错误。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多