我使用symfony 1.4.11。我有前端和后端形式。
前端:
<?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 :(得分: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']);
}
}