2011-06-09 52 views
1

我对Propel ORM使用SF 1.4.8作为项目。我有一个允许用户保存其用户配置文件的操作。它看起来是这样的:Symfony:保存表单对象时出现问题

public function executeEditUser(sfwebRequest $request) 
{ 
    // some code commented out for brevity 
    $tainted_values = $user_profile->toArray(BasePeer::TYPE_FIELDNAME); 

    $this->form->bind(array_merge($tainted_values, $form_params), $file_params); 

    if ($this->form->isValid()) 
    { 
     $this->form->save(); 
     return $this->redirect('@user_account'); 
    }  
} 

用户表单类覆盖了DoSave就会()和更新()方法如下:

protected function doSave($con = null) 
{ 
    $profile = $this->getObject(); 
    // code commented out (saving files etc) 

    return parent::doSave($con); 
} 

public function updateObject($values = null) 
{ 
    $object = parent::updateObject($values); 
    $paththname = $object->getPictPath(); 

    if (!empty($pathname)) 
    { 
     $image_name = basename($pathname); 
     $object->setPictPath($image_name); 
    } 
    return $object; 
} 

当用户编辑并保存配置 - 代码运行的正常,但该对象不会在数据库中更新。我浏览了代码,并在表单的save()方法中,对象执行路径指示没有对对象进行任何更改(即使用户输入的值已正确绑定,并且validate()方法返回true。)

这里是在Apache的错误日志文件打印警告的堆栈跟踪:

[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP Stack trace:, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 1. {main}() /home/voidstar/work/webdev/frameworks/symfony/sites/mywebsite/web/frontend_dev.php:0, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 2. sfContext->dispatch() /home/voidstar/work/webdev/frameworks/symfony/sites/mywebsite/web/frontend_dev.php:13, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 3. sfFrontWebController->dispatch() /lib/vendor/symfony/symfony-1.4.8/lib/util/sfContext.class.php:170, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 4. sfController->forward() /lib/vendor/symfony/symfony-1.4.8/lib/controller/sfFrontWebController.class.php:48, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 5. sfFilterChain->execute() /lib/vendor/symfony/symfony-1.4.8/lib/controller/sfController.class.php:238, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 6. sfRenderingFilter->execute() /lib/vendor/symfony/symfony-1.4.8/lib/filter/sfFilterChain.class.php:53, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 7. sfFilterChain->execute() /lib/vendor/symfony/symfony-1.4.8/lib/filter/sfRenderingFilter.class.php:33, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 8. sfGuardRememberMeFilter->execute() /lib/vendor/symfony/symfony-1.4.8/lib/filter/sfFilterChain.class.php:53, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 9. sfFilterChain->execute() /home/voidstar/work/webdev/frameworks/symfony/sites/mywebsite/plugins/sfGuardPlugin/lib/sfGuardRememberMeFilter.class.php:53, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 10. sfBasicSecurityFilter->execute() /lib/vendor/symfony/symfony-1.4.8/lib/filter/sfFilterChain.class.php:53, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 11. sfFilterChain->execute() /lib/vendor/symfony/symfony-1.4.8/lib/filter/sfBasicSecurityFilter.class.php:72, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 12. sfGoogleAnalyticsFilter->execute() /lib/vendor/symfony/symfony-1.4.8/lib/filter/sfFilterChain.class.php:53, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 13. sfFilterChain->execute() /home/voidstar/work/webdev/frameworks/symfony/sites/mywebsite/plugins/sfGoogleAnalyticsPlugin/lib/filter/sfGoogleAnalyticsFilter.class.php:45, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 14. sfExecutionFilter->execute() /lib/vendor/symfony/symfony-1.4.8/lib/filter/sfFilterChain.class.php:53, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 15. sfExecutionFilter->handleAction() /lib/vendor/symfony/symfony-1.4.8/lib/filter/sfExecutionFilter.class.php:42, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 16. sfExecutionFilter->executeAction() /lib/vendor/symfony/symfony-1.4.8/lib/filter/sfExecutionFilter.class.php:78, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 17. sfActions->execute() /lib/vendor/symfony/symfony-1.4.8/lib/filter/sfExecutionFilter.class.php:92, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 18. userActions->executeEditProfile() /lib/vendor/symfony/symfony-1.4.8/lib/action/sfActions.class.php:60, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 19. sfFormObject->save() /home/voidstar/work/webdev/frameworks/symfony/sites/mywebsite/apps/frontend/modules/user/actions/actions.class.php:68, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 20. UserProfileForm->doSave() /lib/vendor/symfony/symfony-1.4.8/lib/form/addon/sfFormObject.class.php:130, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 21. sfFormObject->doSave() /home/voidstar/work/webdev/frameworks/symfony/sites/mywebsite/lib/form/core/UserProfileForm.class.php:119, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 22. UserProfileForm->updateObject() /lib/vendor/symfony/symfony-1.4.8/lib/form/addon/sfFormObject.class.php:159, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 23. sfFormObject->updateObject() /home/voidstar/work/webdev/frameworks/symfony/sites/mywebsite/lib/form/core/UserProfileForm.class.php:136, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP 24. sfFormPropel->processValues() /lib/vendor/symfony/symfony-1.4.8/lib/form/addon/sfFormObject.class.php:181, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP Warning: array_key_exists() expects parameter 2 to be array, null given in /home/voidstar/work/webdev/frameworks/symfony/sites/mywebsite/lib/model/core/om/BaseUserProfile.php on line 2903, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 
[Thu Jun 09 12:46:49 2011] [error] [client 127.0.0.1] PHP Stack trace:, referer: http://mywebsite.localhost/frontend_dev.php/members/user/profile 

回答