does sfWidgetFormSelect provide a string or an int of the selected item?

Posted by han on Stack Overflow See other posts from Stack Overflow or by han
Published on 2010-12-19T15:33:37Z Indexed on 2010/12/24 0:54 UTC
Read the original article Hit count: 320

Hey guys,

I'm having an annoying problem. I'm trying to find out what fields of a form were changed, and then insert that into a table. I managed to var_dump in doUpdateObjectas shown in the following

public function doUpdateObject($values) 
{ 
    parent::doUpdateObject($values);
    var_dump($this->getObject()->getModified(false));
    var_dump($this->getObject()->getModified(true));
 } 

And it seems like $this->getObject()->getModified seems to work in giving me both before and after values by setting it to either true or false.

The problem that I'm facing right now is that, some how, sfWidgetFormSelect seems to be saving one of my fields as a string. before saving, that exact same field was an int. (I got this idea by var_dump both before and after).

Here is what the results on both var dumps showed:

array(1) {["annoying_field"]=> int(3)} array(1) {["annoying_field"]=>string(1)"3"}

This seems to cause doctrine to think that this is a modification and thus gives a false positive.

In my base form, I have

under $this->getWidgets()
'annoying_field'    => new sfWidgetFormInputText(),

under $this->setValidators
'annoying_field'    => new sfValidatorInteger(array('required' => false)),

and lastly in my configured Form.class.php I have reconfigured the file as such:

$this->widgetSchema['annoying_field'] = new sfWidgetFormSelect(array('choices' => $statuses));

statuses is an array containing values like {""a", "b", "c", "d"}

and I just want the index of the status to be stored in the database.

And also how can I insert the changes into another database table? let's say my Log table?

Any ideas and advice as to why this is happen is appreciated, I've been trying to figure it out and browsing google for various keywords with no avail.

Thanks!

Edit:

ok so I created another field, integer in my schema just for testing. I created an entry, saved it, and edited it.

this time the same thing happened!

© Stack Overflow or respective owner

Related posts about php

Related posts about doctrine