0
votes

I use symfony 1.4.11. I have frontend and backend form.

Frontend :

<?php

{
  public function configure()
  {

     $user = sfContext::getInstance()->getUser()->getGuardUser()->getProfile();

    $this->removeFields();


$this->widgField();
      $this->widgetSchema->setLabels(array(
  'time_id'    => 'Duration *',

   ));
  }

 protected function removeFields()
  {
 unset(

      $this['created_at'],
      $this['updated_at'],
      $this['is_closed'],
      $this['invoice_url'],
      $this['is_cancel']
      );
  }

  protected function widgField()
  {
 $this->widgetSchema['user_id'] = new sfWidgetFormInputHidden();
  }


   protected function  doUpdateObject($values)
  {
    parent::doUpdateObject($values);
    $this->getObject()->setUserId(sfContext::getInstance()->getUser()->getGuardUser()->getId());
  }
}

And Backend:

<?php
class BackendPaymentForm extends PaymentForm
{
  public function configure()
  {
    parent::configure();


  }

  protected function removeFields()
  {
    unset(
     $this['updated_at'],
     $this['created_at'],
     $this['user_id'],
     $this['time_id'],
     $this['invoice_url'],
     $this['is_cancel']

    );
  }
   protected function widgField()
  {

  }

}

?>

Problem is, that I have in frontend doUpdateObject which set user_id , and in backend I need that admin can set one parameter, it is all ok, but it change user_id to admin id... Thank you!

1
Update: I fix it , but I post answer only after 8 hours :(denys281

1 Answers

0
votes

I do not is it good way but it is work:)

class BackendPaymentForm extends PaymentForm
{
  public function configure()
  {
    parent::configure();


  }

  protected function removeFields()
  {
    unset(
     $this['updated_at'],
     $this['created_at'],
     $this['time_id'],
     $this['invoice_url'],
     $this['is_cancel']

    );
  }
   protected function widgField()
  {
$this->widgetSchema['user_id'] = new sfWidgetFormInputHidden();
  }


 protected function  doUpdateObject($values)
  {
    parent::doUpdateObject($values);
    $this->getObject()->setUserId($values['user_id']);
  }
}