我有一个动作类,用于将一些数据保存到数据库中.在动作类中,我通过 url 获取 id.我必须将 id 保存在表中.
I have a action class for saving some data to a database.In action class iam getting a id through url.I have to save the id in table.
我通过 $request->getParameter('id') 获取 id
I am getting the id by $request->getParameter('id')
我用这个代码保存
$this->form->bind($request->getParameter('question_answers'));如果 ($this->form->isValid()){$this->form->save();$this->redirect('@homepage');
$this->form->bind($request->getParameter('question_answers')); if ($this->form->isValid()) { $this->form->save(); $this->redirect('@homepage'); }
在模型类中,我使用了一个覆盖保存方法来保存额外的字段
in model class i used a override save method to save extra field
公共函数保存(Doctrine_Connection $conn = null){如果 ($this->isNew()){
public function save(Doctrine_Connection $conn = null) { if ($this->isNew()) {
$now=date('Y-m-d H:i:s', time()); $this->setPostedAt($now);}return parent::save($conn);所以我想在这里获取 id 值.那么如何将 id 值从动作类传递到模型类
} return parent::save($conn); so i want to get the id value here . So how can i pass id value from action class to model class
是在操作类本身中保存 id 的任何其他方式提前致谢
is any-other way to save the id in action class itself Thanks in advance
推荐答案就用
$this->form->getObject()->setQuestionId($request->getParameter('id'));$this->form->save();
$this->form->getObject()->setQuestionId($request->getParameter('id')); $this->form->save();
QuestionId=字段名称
QuestionId=field name
$request->getParameter('id')= 是默认值
$request->getParameter('id')= is the default value
更多推荐
将值从动作类传递到 symfony 中的模型类
发布评论