将值从动作类传递到 symfony 中的模型类 [英] Passing values from action class to model class in symfony

查看:19
本文介绍了将值从动作类传递到 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 中的模型类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆