将值从动作类传递到 symfony 中的模型类

编程入门 行业动态 更新时间:2024-10-24 13:23:11
本文介绍了将值从动作类传递到 symfony 中的模型类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个动作类,用于将一些数据保存到数据库中.在动作类中,我通过 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 中的模型类

本文发布于:2023-10-07 17:32:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470038.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动作类   模型   symfony

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!