单独模块完成后如何更新sfUserProfile? postSave() 不起作用

发布于 2024-12-03 12:44:54 字数 3631 浏览 0 评论 0原文

我有一个注册表单,其中包括 sfRegistration 和 sfProfile,完成后,它会重定向到另一个表单 - 以确定用户的公司,并且是一个单独的模块。 sfProfile 包含公司模块中的一个字段...corporate_id。但由于 Corporate_id 不是个人资料的一部分,因此在注册时不会包含它。这里的问题是,完成公司模块后,使用新完成的公司模块的corporate_id更新用户个人资料的最佳方法是什么?我尝试了这个:

public function postSave()
{
$corpId = $this->form->getId();
$logged_user_id = sfContext::getInstance()->getUser()->getId();
Doctrine_Query::create()
->update('sf_guard_user_profile p')
->set('p.corporate_id', $corpId)
->where('p.user_id' == $logged_user_id )
->execute();
}

放入公司模块的操作中,但它没有使用company_id更新配置文件。

建议?

更新 - 根据请求,这里是请求的信息:(我的>>lib>form>>doctrine>>CorporationForm.class.php是空的......我正在尝试我的actions类中的函数......其中可能是问题所在)。澄清一下,我只需要在用户完成公司模块后使用新创建的 Corporate_id 更新用户的个人资料。
和我的架构:

sfGuardUser:
  actAs: [Timestampable]
  columns:
    first_name: string(255)
    last_name: string(255)
    email_address:
      type: string(255)
      notnull: true
      unique: true
    username:
      type: string(128)
      notnull: true
      unique: true
    algorithm:
      type: string(128)
      default: sha1
      notnull: true
    salt: string(128)
    password: string(128)
    is_active:
      type: boolean
      default: 1
    is_super_admin:
      type: boolean
      default: false
    last_login:
      type: timestamp
  indexes:
    is_active_idx:
      fields: [is_active]
  relations:
    Groups:
      class: sfGuardGroup
      local: user_id
      foreign: group_id
      refClass: sfGuardUserGroup
      foreignAlias: Users
    Permissions:
      class: sfGuardPermission
      local: user_id
      foreign: permission_id
      refClass: sfGuardUserPermission
      foreignAlias: Users

sfGuardUserProfile:
 actAs:            { Timestampable: ~ }
 columns:
  id: { type: integer, primary: true, notnull: true, autoincrement: true, unique: true }
  user_id: { type: integer }
  corporate_id: { type: integer }
  type_id: { type: integer, notnull: true }
  prefix_id: { type: integer }
  middle_name: { type: string(55) }
  suffix_id: { type: integer }
  phone: { type: string(55), notnull: true }
  home_address_line_one: { type: string }
  home_address_line_two: { type: string }
  home_city: { type: string }
  state_id: { type: integer }
  home_zip: { type: integer } 
 relations:
  User: { class: sfGuardUser, local: user_id, foreign: id, type: one, foreignType: one,     foreignAlias: Profile }
  Type: { local: type_id, foreign: id, type: one, foreignAlias: Types } 
  Prefix: { local: prefix_id, foreign: id, type: one, foreignAlias: Prefixs } 
  Suffix: { local: suffix_id, foreign: id, type: one, foreignAlias: Suffixs }   
  State:  { local: state_id, foreign: id, foreignAlias: States }  
  Corporation: { local: corporate_id, foreign: id, foreignAlias: Corporations }

Corporation:
  columns:
   id:             { type: integer, primary: true, notnull: true, autoincrement: true,    unique: true }
   user_id:        { type: integer }
   name:           { type: string(55), notnull: true }
   address_line1:   { type: string(255), notnull: true }
   address_line2:   { type: string(255), notnull: true }
   city:           { type: string(25), notnull: true }
   state_id:       { type: integer, notnull: true }
   zip:            { type: string(25), notnull: true }
   phone:          { type: string(25), notnull: true }
   email:          { type: string(100), notnull: true }
   website:        { type: string(100) }
   logo:           { type: string(255) }
  relations:
    User: { class: sfGuardUser, local: user_id, foreign: id, foreignAlias: Users }

I have a registration form that includes sfRegistration and sfProfile, which after completion, get's redirected to another form - to determine the user's corporation and is a seperate module. The sfProfile includes a field from the corporation module... the corporate_id. But since the corporate_id is not part of the profile, it does not get included at registration time. Here's the question, after completion of the corporation module, what is the best way to update the user's profile with the corporate_id of the newly completed corporation module? I tried this:

public function postSave()
{
$corpId = $this->form->getId();
$logged_user_id = sfContext::getInstance()->getUser()->getId();
Doctrine_Query::create()
->update('sf_guard_user_profile p')
->set('p.corporate_id', $corpId)
->where('p.user_id' == $logged_user_id )
->execute();
}

placed into the action of the company module, but it is not updating the profile with the company_id.

Suggestions?

UPDATE - per request, here is the information requested: (my >>lib>form>>doctrine>>CorporationForm.class.php is empty... I was trying my functions in the actions class... which may be the issue). Just to clarify, I just need to update the user's profile with the newly created corporate_id after the user completes the corporation module.
And my schema:

sfGuardUser:
  actAs: [Timestampable]
  columns:
    first_name: string(255)
    last_name: string(255)
    email_address:
      type: string(255)
      notnull: true
      unique: true
    username:
      type: string(128)
      notnull: true
      unique: true
    algorithm:
      type: string(128)
      default: sha1
      notnull: true
    salt: string(128)
    password: string(128)
    is_active:
      type: boolean
      default: 1
    is_super_admin:
      type: boolean
      default: false
    last_login:
      type: timestamp
  indexes:
    is_active_idx:
      fields: [is_active]
  relations:
    Groups:
      class: sfGuardGroup
      local: user_id
      foreign: group_id
      refClass: sfGuardUserGroup
      foreignAlias: Users
    Permissions:
      class: sfGuardPermission
      local: user_id
      foreign: permission_id
      refClass: sfGuardUserPermission
      foreignAlias: Users

sfGuardUserProfile:
 actAs:            { Timestampable: ~ }
 columns:
  id: { type: integer, primary: true, notnull: true, autoincrement: true, unique: true }
  user_id: { type: integer }
  corporate_id: { type: integer }
  type_id: { type: integer, notnull: true }
  prefix_id: { type: integer }
  middle_name: { type: string(55) }
  suffix_id: { type: integer }
  phone: { type: string(55), notnull: true }
  home_address_line_one: { type: string }
  home_address_line_two: { type: string }
  home_city: { type: string }
  state_id: { type: integer }
  home_zip: { type: integer } 
 relations:
  User: { class: sfGuardUser, local: user_id, foreign: id, type: one, foreignType: one,     foreignAlias: Profile }
  Type: { local: type_id, foreign: id, type: one, foreignAlias: Types } 
  Prefix: { local: prefix_id, foreign: id, type: one, foreignAlias: Prefixs } 
  Suffix: { local: suffix_id, foreign: id, type: one, foreignAlias: Suffixs }   
  State:  { local: state_id, foreign: id, foreignAlias: States }  
  Corporation: { local: corporate_id, foreign: id, foreignAlias: Corporations }

Corporation:
  columns:
   id:             { type: integer, primary: true, notnull: true, autoincrement: true,    unique: true }
   user_id:        { type: integer }
   name:           { type: string(55), notnull: true }
   address_line1:   { type: string(255), notnull: true }
   address_line2:   { type: string(255), notnull: true }
   city:           { type: string(25), notnull: true }
   state_id:       { type: integer, notnull: true }
   zip:            { type: string(25), notnull: true }
   phone:          { type: string(25), notnull: true }
   email:          { type: string(100), notnull: true }
   website:        { type: string(100) }
   logo:           { type: string(255) }
  relations:
    User: { class: sfGuardUser, local: user_id, foreign: id, foreignAlias: Users }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我恋#小黄人 2024-12-10 12:44:54

以您的形式:

public function  doUpdateObject($values)
  {

   parent::doUpdateObject($values);
   $this->getObject()->setCorporateId(your value);

}

例如
//应用程序/前端/yourmodule/action.class.php

protected function processForm(sfWebRequest $request, sfForm $form)
    {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {

       $corporation = $form->save();
       $user_id=$this->getUser()->getGuardUser()->getId();
       $profile = Doctrine_Core::getTable('sfGuardUserProfile')->findOneByUserId($user_id);
       $profile->setCorporateId('your value');

In your form:

public function  doUpdateObject($values)
  {

   parent::doUpdateObject($values);
   $this->getObject()->setCorporateId(your value);

}

For example
//apps/frontend/yourmodule/action.class.php

protected function processForm(sfWebRequest $request, sfForm $form)
    {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {

       $corporation = $form->save();
       $user_id=$this->getUser()->getGuardUser()->getId();
       $profile = Doctrine_Core::getTable('sfGuardUserProfile')->findOneByUserId($user_id);
       $profile->setCorporateId('your value');
冷清清 2024-12-10 12:44:54

不要忘记 ->save();

    public function setId() 
  {
        $user_id = $this->getUser()->getGuardUser()->getId();
        $corp_id = 1;
        $user_profile = Doctrine_Core::getTable('sfGuardUserProfile')->findOneByUserId($user_id);
        $user_profile->setCorporateId($corp_id)->save();
   }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {            
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
        self::setId();        
        $corporation = $form->save();    
        $this->redirect('dashboard/index');      
    }
  }

Don't forget the ->save();

    public function setId() 
  {
        $user_id = $this->getUser()->getGuardUser()->getId();
        $corp_id = 1;
        $user_profile = Doctrine_Core::getTable('sfGuardUserProfile')->findOneByUserId($user_id);
        $user_profile->setCorporateId($corp_id)->save();
   }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {            
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
        self::setId();        
        $corporation = $form->save();    
        $this->redirect('dashboard/index');      
    }
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文