Hello,
I have some fields in my database with NULL as their default value. With the form created by the yiic command, these fields display by default the "NULL" string. I would want to display an empty string instead. How can i do that ? I browse the docs but i can't find anything related to this subject.
Thank you very much.
Regards,
Stéphane.
Page 1 of 1
How to avoid the "NULL" string by default in form fields ?
#2
Posted 30 October 2009 - 07:52 AM
you have to change Null to Not Null and set the default value to an empty string in you database. use phpmyadmin or something to edit you field in your tables.
#3
Posted 30 October 2009 - 08:05 AM
Yes, it's a solution. But i was wondering if there is an other solution on the Yii side ? May be like a post-filter which would automatically convert the "NULL" string to the empty string if the SQL value is null before displaying the form.
In my case, i can modify my database structure so i could indeed change the default value in my table. But sometimes you can't make this kind of change.
Thank you.
Regards,
Stéphane.
In my case, i can modify my database structure so i could indeed change the default value in my table. But sometimes you can't make this kind of change.
Thank you.
Regards,
Stéphane.
#4
Posted 30 October 2009 - 09:35 AM
i don't think so. because the database puts the NULL value into the fields and not Yii.
#5
Posted 30 October 2009 - 10:01 AM
bas_vdl, on 30 October 2009 - 09:35 AM, said:
i don't think so. because the database puts the NULL value into the fields and not Yii.
Sure but Yii reads the fields values from the database. So, there is no way to convert the fields values read in the database by Yii just before the display in the form ? Something like this :
DB values -> Yii read these values -> ** Filter to convert null to empty string ** -> Form display (without any null)
I'm not sure to be very clear in my explanation... :-)
#6
Posted 30 October 2009 - 10:15 AM
i'm sorry i was thinking about inserting data into the database. maybe you can use the afterFind() method to replace NULL values by an empty string.
#7
Posted 02 November 2009 - 05:53 AM
Ah, yes, that should do the trick. I wasn't aware of these AR methods.
Thank you very much for your help.
Regards,
Stéphane.
Thank you very much for your help.
Regards,
Stéphane.
Share this topic:
Page 1 of 1

Help












