- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用我的第一个嵌入式表单 (SF2.1 + Doctrine2)
实体:
<?php
namespace Chris\BabelBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
*/
class Needs
{
/**
* @ORM\GeneratedValue
* @ORM\Id
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Projects")
* @Assert\NotBlank()
*/
private $relatedproject;
/**
* @ORM\ManyToOne(targetEntity="Activities")
* @Assert\NotBlank()
*/
private $relatedactivity;
/**
* @ORM\ManyToOne(targetEntity="Jobs")
* @Assert\NotBlank()
*/
private $relatedjob;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
*/
private $lastname;
/**
* @ORM\ManyToOne(targetEntity="Experiences")
* @Assert\NotBlank()
*/
private $relatedexperience;
/**
* @ORM\ManyToOne(targetEntity="Plants")
* @Assert\NotBlank()
*/
private $maintrainingplant;
/**
* @ORM\Column(type="date")
* @Assert\NotBlank()
*/
private $trainingneedstart;
/**
* @ORM\Column(type="date")
* @Assert\NotBlank()
*/
private $readytowork;
/**
* @var ArrayCollection $trainings
*
* @ORM\OneToMany(targetEntity="Trainings", mappedBy="training", cascade={"persist", "remove", "merge"})
*/
private $trainings;
/**
* Constructor
*/
public function __construct()
{
$this->trainings = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set firstname
*
* @param string $firstname
* @return Needs
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* Get firstname
*
* @return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set lastname
*
* @param string $lastname
* @return Needs
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get lastname
*
* @return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set trainingneedstart
*
* @param \DateTime $trainingneedstart
* @return Needs
*/
public function setTrainingneedstart($trainingneedstart)
{
$this->trainingneedstart = $trainingneedstart;
return $this;
}
/**
* Get trainingneedstart
*
* @return \DateTime
*/
public function getTrainingneedstart()
{
return $this->trainingneedstart;
}
/**
* Set readytowork
*
* @param \DateTime $readytowork
* @return Needs
*/
public function setReadytowork($readytowork)
{
$this->readytowork = $readytowork;
return $this;
}
/**
* Get readytowork
*
* @return \DateTime
*/
public function getReadytowork()
{
return $this->readytowork;
}
/**
* Set relatedproject
*
* @param \Chris\BabelBundle\Entity\Projects $relatedproject
* @return Needs
*/
public function setRelatedproject(\Chris\BabelBundle\Entity\Projects $relatedproject = null)
{
$this->relatedproject = $relatedproject;
return $this;
}
/**
* Get relatedproject
*
* @return \Chris\BabelBundle\Entity\Projects
*/
public function getRelatedproject()
{
return $this->relatedproject;
}
/**
* Set relatedactivity
*
* @param \Chris\BabelBundle\Entity\Activities $relatedactivity
* @return Needs
*/
public function setRelatedactivity(\Chris\BabelBundle\Entity\Activities $relatedactivity = null)
{
$this->relatedactivity = $relatedactivity;
return $this;
}
/**
* Get relatedactivity
*
* @return \Chris\BabelBundle\Entity\Activities
*/
public function getRelatedactivity()
{
return $this->relatedactivity;
}
/**
* Set relatedjob
*
* @param \Chris\BabelBundle\Entity\Jobs $relatedjob
* @return Needs
*/
public function setRelatedjob(\Chris\BabelBundle\Entity\Jobs $relatedjob = null)
{
$this->relatedjob = $relatedjob;
return $this;
}
/**
* Get relatedjob
*
* @return \Chris\BabelBundle\Entity\Jobs
*/
public function getRelatedjob()
{
return $this->relatedjob;
}
/**
* Set relatedexperience
*
* @param \Chris\BabelBundle\Entity\Experiences $relatedexperience
* @return Needs
*/
public function setRelatedexperience(\Chris\BabelBundle\Entity\Experiences $relatedexperience = null)
{
$this->relatedexperience = $relatedexperience;
return $this;
}
/**
* Get relatedexperience
*
* @return \Chris\BabelBundle\Entity\Experiences
*/
public function getRelatedexperience()
{
return $this->relatedexperience;
}
/**
* Set maintrainingplant
*
* @param \Chris\BabelBundle\Entity\Plants $maintrainingplant
* @return Needs
*/
public function setMaintrainingplant(\Chris\BabelBundle\Entity\Plants $maintrainingplant = null)
{
$this->maintrainingplant = $maintrainingplant;
return $this;
}
/**
* Get maintrainingplant
*
* @return \Chris\BabelBundle\Entity\Plants
*/
public function getMaintrainingplant()
{
return $this->maintrainingplant;
}
/**
* Add trainings
*
* @param \Chris\BabelBundle\Entity\Trainings $trainings
* @return Needs
*/
public function addTraining(\Chris\BabelBundle\Entity\Trainings $trainings)
{
$this->trainings[] = $trainings;
return $this;
}
/**
* Remove trainings
*
* @param \Chris\BabelBundle\Entity\Trainings $trainings
*/
public function removeTraining(\Chris\BabelBundle\Entity\Trainings $trainings)
{
$this->trainings->removeElement($trainings);
}
/**
* Get trainings
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getTrainings()
{
return $this->trainings;
}
public function __toString() {return $this->getFirstname();}
}
<?php
namespace Chris\BabelBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*/
class Trainings
{
/**
* @ORM\GeneratedValue
* @ORM\Id
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Plants")
* @Assert\NotBlank()
*/
private $trainingplant;
/**
* @ORM\Column(type="date")
* @Assert\NotBlank()
*/
private $trainingstart;
/**
* @ORM\Column(type="date")
* @Assert\NotBlank()
*/
private $trainingend;
/**
* @var Needs $trainings
*
* @ORM\ManyToOne(targetEntity="Needs", inversedBy="trainings", cascade={"persist", "remove", "merge"})
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="Needs_id", referencedColumnName="id")
* })
*/
private $training;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set trainingstart
*
* @param \DateTime $trainingstart
* @return Trainings
*/
public function setTrainingstart($trainingstart)
{
$this->trainingstart = $trainingstart;
return $this;
}
/**
* Get trainingstart
*
* @return \DateTime
*/
public function getTrainingstart()
{
return $this->trainingstart;
}
/**
* Set trainingend
*
* @param \DateTime $trainingend
* @return Trainings
*/
public function setTrainingend($trainingend)
{
$this->trainingend = $trainingend;
return $this;
}
/**
* Get trainingend
*
* @return \DateTime
*/
public function getTrainingend()
{
return $this->trainingend;
}
/**
* Set trainingplant
*
* @param \Chris\BabelBundle\Entity\Plants $trainingplant
* @return Trainings
*/
public function setTrainingplant(\Chris\BabelBundle\Entity\Plants $trainingplant = null)
{
$this->trainingplant = $trainingplant;
return $this;
}
/**
* Get trainingplant
*
* @return \Chris\BabelBundle\Entity\Plants
*/
public function getTrainingplant()
{
return $this->trainingplant;
}
/**
* Set training
*
* @param \Chris\BabelBundle\Entity\Needs $training
* @return Trainings
*/
public function setTraining(\Chris\BabelBundle\Entity\Needs $training = null)
{
$this->training = $training;
return $this;
}
/**
* Get training
*
* @return \Chris\BabelBundle\Entity\Needs
*/
public function getTraining()
{
return $this->training;
}
}
2 个 Controller :
<?php
namespace Chris\BabelBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chris\BabelBundle\Entity\Needs;
use Chris\BabelBundle\Form\NeedsType;
/**
* Needs controller.
*
*/
class NeedsController extends Controller
{
/**
* Lists all Needs entities.
*
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('ChrisBabelBundle:Needs')->findAll();
return $this->render('ChrisBabelBundle:Needs:index.html.twig', array(
'entities' => $entities,
));
}
/**
* Finds and displays a Needs entity.
*
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChrisBabelBundle:Needs')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Needs entity.');
}
return $this->render('ChrisBabelBundle:Needs:show.html.twig', array(
'entity' => $entity, ));
}
/**
* Displays a form to create a new Needs entity.
*
*/
public function newAction()
{
$entity = new Needs();
$form = $this->createForm(new NeedsType(), $entity);
return $this->render('ChrisBabelBundle:Needs:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Creates a new Needs entity.
*
*/
public function createAction(Request $request)
{
$entity = new Needs();
$form = $this->createForm(new NeedsType(), $entity);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('needs_show', array('id' => $entity->getId())));
}
return $this->render('ChrisBabelBundle:Needs:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Displays a form to edit an existing Needs entity.
*
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChrisBabelBundle:Needs')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Needs entity.');
}
$editForm = $this->createForm(new NeedsType(), $entity);
return $this->render('ChrisBabelBundle:Needs:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
));
}
/**
* Edits an existing Needs entity.
*
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChrisBabelBundle:Needs')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Needs entity.');
}
$editForm = $this->createForm(new NeedsType(), $entity);
$editForm->bind($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('needs_edit', array('id' => $id)));
}
return $this->render('ChrisBabelBundle:Needs:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
));
}
/**
* Deletes a Needs entity.
*
*/
public function deleteAction($id)
{
$em = $this->container->get('doctrine')->getEntityManager();
$metier = $em->find('ChrisBabelBundle:Needs', $id);
if (!$metier)
{
throw new NotFoundHttpException("Need not found");
}
$em->remove($metier); $em->flush();
return $this->redirect($this->generateUrl('needs'));
}
}
<?php
namespace Chris\BabelBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chris\BabelBundle\Entity\Trainings;
use Chris\BabelBundle\Form\TrainingsType;
/**
* Trainings controller.
*
*/
class TrainingsController extends Controller
{
/**
* Lists all Trainings entities.
*
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('ChrisBabelBundle:Trainings')->findAll();
return $this->render('ChrisBabelBundle:Trainings:index.html.twig', array(
'entities' => $entities,
));
}
/**
* Finds and displays a Trainings entity.
*
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChrisBabelBundle:Trainings')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Trainings entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChrisBabelBundle:Trainings:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(), ));
}
/**
* Displays a form to create a new Trainings entity.
*
*/
public function newAction()
{
$entity = new Trainings();
$form = $this->createForm(new TrainingsType(), $entity);
return $this->render('ChrisBabelBundle:Trainings:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Creates a new Trainings entity.
*
*/
public function createAction(Request $request)
{
$entity = new Trainings();
$form = $this->createForm(new TrainingsType(), $entity);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('trainings_show', array('id' => $entity->getId())));
}
return $this->render('ChrisBabelBundle:Trainings:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Displays a form to edit an existing Trainings entity.
*
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChrisBabelBundle:Trainings')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Trainings entity.');
}
$editForm = $this->createForm(new TrainingsType(), $entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChrisBabelBundle:Trainings:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Edits an existing Trainings entity.
*
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChrisBabelBundle:Trainings')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Trainings entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createForm(new TrainingsType(), $entity);
$editForm->bind($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('trainings_edit', array('id' => $id)));
}
return $this->render('ChrisBabelBundle:Trainings:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a Trainings entity.
*
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChrisBabelBundle:Trainings')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Trainings entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('trainings'));
}
private function createDeleteForm($id)
{
return $this->createFormBuilder(array('id' => $id))
->add('id', 'hidden')
->getForm()
;
}
}
最后是表格:
<?php
namespace Chris\BabelBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class NeedsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstname')
->add('lastname')
->add('trainingneedstart')
->add('readytowork')
->add('relatedproject')
->add('relatedactivity')
->add('relatedjob')
->add('relatedexperience')
->add('maintrainingplant')
// Ajout du formulaire imbriqué des trainings en collection
->add('trainings', 'collection', array('type' => new TrainingsType(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Chris\BabelBundle\Entity\Needs'
));
}
public function getName()
{
return 'chris_babelbundle_needstype';
}
}
<?php
namespace Chris\BabelBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class TrainingsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('trainingstart')
->add('trainingend')
->add('trainingplant')
->add('training')
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Chris\BabelBundle\Entity\Trainings'
));
}
public function getName()
{
return 'chris_babelbundle_trainingstype';
}
}
除保存的培训不包含数据库中的需求 ID 外,大部分工作正常,因此在编辑需求时我无法检索多个培训。
最佳答案
最后我在法语 IRC 的帮助下找到了解决方案 :)
我只需要像这样修改 Needs 实体:
/**
* Add trainings
*
* @param \Chris\BabelBundle\Entity\Trainings $trainings
* @return Needs
*/
public function addTraining(\Chris\BabelBundle\Entity\Trainings $trainings)
{
$this->trainings[] = $trainings;
$trainings->setTraining($this);
return $this;
}
关于doctrine-orm - symfony2 : unable to save parent id in embedded object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15050909/
ASIDE:是的,这可以被认为是一个主观问题,但我希望从回答的统计数据中得出结论。 有各种各样的计算设备。它们的物理尺寸、计算能力和电力各不相同。我想知道嵌入式开发人员认为什么是使系统“嵌入式”的决定
当我听到这个时,我总是想到移动设备。但为什么硬件“嵌入”在那里?整个设备不就是硬件吗?为什么个人电脑没有嵌入式硬件系统? 最佳答案 在当今世界,嵌入式仅指具有以下一项或多项特征的系统: 单一用途(即,
我想测试嵌入式 PowerBI 所以我下载了 the sample app能够发布 pbix 文件并嵌入它。 所以我创建了最简单的 PowerBI 文件,可以使用 Azure SQL 制作,使用 Di
我需要问几个关于词嵌入的问题......可能是基本的。 当我们转换一个词的 one-hot 向量时,例如 king [0 0 0 1 0]嵌入向量 E = [0.2, 0.4, 0.2, 0.2] .
我想知道如何将 CEF 添加到我的 Yocto 项目中。此时,我还没有对项目进行任何修改。它由我们的电路板制造商提供。该板有一个ARM 9。 最佳答案 直接在 CEF 论坛上问这个问题是个好主意,可能
实体是否可以访问其 Embedded 对象的 Embedded?例如: @Embeddable public class Address { @Embedded protected A
我有一个类似于这个的 Morphia 架构: @Entity class BlogEntry { @Embedded List comments } @Embedded class B
我的 pom.xml 中有以下插件配置: com.day.jcr.vault maven-vault-plugi
直到现在,我仍然对 Openembedded-core 和 meta-openembedded 中的食谱感到困惑。很多时候,很难将食谱放在正确的目录中。它们真的很相似,但在食谱的内容上似乎如此不同。
我正在尝试使用此处找到的 Tensorflow 运行单词教程的矢量表示: http://www.tensorflow.org/tutorials/word2vec/index.md 第一个脚本 wor
谁能帮我解释一下 power BI premium 和 power BI Embedded 之间的区别? 最佳答案 Power BI Embedded 容量(也称为 SKU)是 billed hour
我在执行一个 MongoDB 请求时遇到了一些麻烦。我在 Node.js 上下文中使用 MongoDB 3.2 和 Mongoose。这是文档: { _id: ObjectId('12345'),
Xcode 常规选项卡中的“嵌入式二进制文件”和构建阶段选项卡中的“嵌入式框架”有什么区别? General 选项卡中的“Linked Frameworks”和 Build Phrases 选项卡中的
我正在尝试执行 maven install在 pom 上,显示的结果是: Grave: SEC5054: Certificate has expired 此结果会在测试执行开始后立即出现。 我一直在搜
我正在研究 ppc32 和 ppc64 架构来为我的编译器实现一个新的后端,但是我对一个函数的序言有疑问,我已经阅读了几个关于 PowerPC 的 IBM 文档,但是我读到的关于堆栈的信息很少.一个程
我大部分时间都在使用 Atmel Studio 等工具和 IDE 开发微 Controller ,并抽象出幕后发生的事情。 假设在这种情况下,我们直接从闪存执行代码,这在嵌入式系统中可能是这种情况。
我刚刚发现我在(Cortex M0)上编写代码的ARM不支持未对齐的内存访问。 现在,在我的代码中,我使用了很多打包结构,并且从未收到任何警告或硬故障,所以当Cortex不允许不对齐访问时,Corte
我正在研究 Uboot bootstrap 。我有一些关于 Bootloader 的功能和它要处理的应用程序的基本问题: Q1:据我所知,引导加载程序用于将应用程序下载到内存中。在互联网上,我还发现引
我想了解基本的RISC架构。经过一些研发,我想使用MIPS架构。但是,我没有获得有关带有MIPS处理器的嵌入式开发板的良好信息。 如果有人可以提出好的董事会建议,将会有很大的帮助。 问候, 拉姆吉 最
考虑我们正在为裸机 MCU 编写固件,即没有操作系统。有人告诉我不可能(非法?)将参数传递给中断处理函数? 我无法准确理解为什么会这样?这有什么问题? 附注。是否可以在某些 RTOS-es、嵌入式 L
我是一名优秀的程序员,十分优秀!