2011-07-08 58 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']); 
    } 
}