Insert NULL into DB when string is empty

I would like to insert NULL values into my database whenever a textfield is left blank. Is there an easy way to specify this for a whole project in Yii?

I just started with Yii so maybe I'm wrong but don't you can just set the default field values to NULL in your database table or will Yii insert the fields anyhow (eg with a blank string)?

Set the corresponding attribute value to be null. You may do this conversion (from empty string to null) in beforeSave().