Symfony:保存表单对象时出现问题

问题描述 投票:0回答:1

我在一个项目中使用 SF 1.4.8 和 Propel ORM。我有一个允许用户保存其用户个人资料的操作。它看起来像这样:

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

当用户编辑并保存配置文件时 - 代码正常运行,但对象不会在数据库中更新。我单步执行了代码,在表单的 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
php orm symfony1 symfony-forms propel
1个回答
0
投票

答案与此问题相同:Symfony 表单值缺失

即重写 postValidate() 方法不返回 $values 是罪魁祸首!

© www.soinside.com 2019 - 2024. All rights reserved.