What is the best way to apply the trim() function to all input data automatically in Yii? Currently all trailing and leading spaces end up in my database.
Page 1 of 1
trim all input data
#2
Posted 18 June 2009 - 02:14 PM
I suppose you could:
- use validation to check for such things before saving the record
or
- use beforeSave() to transparently trim data before saving..
just a thought
- use validation to check for such things before saving the record
or
- use beforeSave() to transparently trim data before saving..
just a thought
#3
Posted 18 June 2009 - 03:05 PM
Thanx, overriding the beforeSave() method seems the best way, though I was hoping that there is some configuration setting in Yii where I could specify general filters for inputs.
#4
Posted 18 June 2009 - 03:29 PM
Indeed, beforeSave() is what i meant, i will edit the above to correct the typo.
#5
Posted 01 March 2012 - 08:52 AM
I think trimming should be done in beforeValidate. The reason for this is that some validations might even fail with surrounding spaces to an input. If an email field for example, will never validate if there are spaces around the actual email address. So, beforeValidate makes sure things are in proper shape before validation and off course it'll also be saved in database the same way.
But, I was wondering if there is a built in way to do this with Yii. There should be something like this out of the box. In Kohana it used to happen automatically. If I have a large set of inputs, doing this every time for each input could be time consuming.
But, I was wondering if there is a built in way to do this with Yii. There should be something like this out of the box. In Kohana it used to happen automatically. If I have a large set of inputs, doing this every time for each input could be time consuming.
#6
Posted 01 March 2012 - 09:41 AM
This topic is three years old, mind you.
"Less noise - more signal"
Share this topic:
Page 1 of 1