Yii Framework Forum: How to avoid the "NULL" string by default in form fields ? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to avoid the "NULL" string by default in form fields ? Rate Topic: -----

#1 User is offline   Stéphane 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 15-October 09

Posted 29 October 2009 - 04:40 AM

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.
0

#2 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

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.
0

#3 User is offline   Stéphane 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 15-October 09

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.
0

#4 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

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.
0

#5 User is offline   Stéphane 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 15-October 09

Posted 30 October 2009 - 10:01 AM

View Postbas_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... :-)
0

#6 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

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.
0

#7 User is offline   Stéphane 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 15-October 09

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users