开发者

How to stop Yii framework trimming string before saving to DB

开发者 https://www.devze.com 2023-04-13 03:55 出处:网络
I have an unfortunate requirement which, despite my gasps of disgust and protest, have to be enforced.

I have an unfortunate requirement which, despite my gasps of disgust and protest, have to be enforced.

I have to store a string in the database (sqlserver) untrimmed. (Yes I know, very bad!)

Unfortunately it is data from another system. The preceding whitespace is not a consistent length nor is there any way for me to calculate the number of spaces before 开发者_如何学Cthe string.

This means I have to store the string with the preceding whitespace (sic)

So the question is, How can I prevent the Yii framework trimming the string automatically.

Thanks in advance.

Example code:

$mod = MyModel::model()->findByPk(1);
$mod->string = '  My String'; // <- Yii please don't trim the preceding whitespace.
$mod->save(); // <- Yii automatically trims the string NO DON'T DO IT


While I can think of a few rather complicated work-arounds, the easiest method may be to simply urlencode or otherwise tokenize the whitespace -- the main down-side is you have to make sure any retrieval method decodes it properly.

0

精彩评论

暂无评论...
验证码 换一张
取 消