Symfony 后端表单
我使用 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 更改为管理员 ID。 .. 谢谢你!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为这是好方法,但它是工作:)
I do not is it good way but it is work:)