duanlou2917 2010-12-19 15:33
浏览 49
已采纳

sfWidgetFormSelect提供所选项的字符串或int吗?

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!

  • 写回答

2条回答 默认 最新

  • duanbiao4035 2010-12-24 00:48
    关注

    Okay, It turns out I forgot to do a custom validator to use the array key instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀