簡體   English   中英

yii2模型str_replace()用於所有屬性

[英]yii2 model str_replace() for all attributes

hello 's被保存為數據庫中的hello \\'s

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

所有包含\\'數據應替換為'

我應該在模型中進行哪些更改以處理該問題?

我會做

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);
}

在Yii2中,如果我們添加任何帶有單引號的值,則默認情況下,如果要在視圖頁面中顯示,則添加時不帶反斜杠。

是否要在保存前或將其隱式更改之前將單引號與反斜杠轉換?

如果其隱式更改,則可以檢查PHP.ini中的magic_quote_gpc設置。 應該關閉了。 如果您的PHP版本低於5.4,則應更改magic_quote設置。 如果您的PHP版本> 5.4,則應該有其他錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM