2011-07-08 56 views
0

我使用symfony 1.4.11。我有前端和后端形式。Symfony后端形式

前端:

<?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()); 
    } 
} 

和后端:

<?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() 
    { 

    } 

} 

?> 

问题是,我在前台doUpdateObject其设置USER_ID,并在后台我需要一个管理员可以设置一个参数,它都可以,但它将user_id更改为admin id ...谢谢!

+0

更新:我修复它,但我只有8小时后发布的答案:( – denys281

回答

0

我也不是好办法,但它是工作:)

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']); 
    } 
}