2011-06-09 3 views
1

Я использую SF 1.4.8 с Propel ORM для проекта. У меня есть действие, которое позволяет пользователю сохранять свой профиль пользователя. Это выглядит примерно так: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() и Update() методы следующим образом:

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; 
} 

Когда правки пользователя и сохраняет профиль - код работает как normal, но объект не обновляется в базе данных. Я прошел через код и в методе save() формы, путь выполнения объекта указывает, что никаких изменений в объект не было внесено (даже если введенные пользователем значения были правильно привязаны, и метод validate() вернул true.

Вот StackTrace предупреждений печататься в журнал ошибок 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 

ответ

0

Ответ такой же, как на этот вопрос: Symfony form values missing

т.е. перекрываться postValidate() метод не возвращающей $ значения прошел преступник

Смежные вопросы