我有实体技能,技能有实体语言和关系ManyToMany,我在这个表单中创建表单编辑和发布实体技能,每个字段都是空的,但技能有名称和语言。为什么模板中的空字段?我没有创建新的,我编辑现有的实体。我做错了什么?当我调试时,我看到技能不是空场。请帮助(((sreeen_show,screen_edit 我的行动: 在行动中我尝试
$ln = $entity->getLanguage()->getValues();
并拥有所有技能语言,为什么表格不检查这种语言?
/**
* Edit skill.
*
* @Route("/skills/edit/{id}", name="skill_edit")
* @Method({"GET", "POST"})
* @Template()
* @ParamConverter("entity", class="MyBundle:Skill")
*/
public function editSkillsAction(Request $request, $entity)
{
$em = $this->getDoctrine()->getManager();
$form = $this->createForm(new SkillType(), $entity);
$form->submit($request);
if ($request->isMethod('POST')) {
if ($form->isValid()) {
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('skills_show'));
}
}
return array(
'debug' => true,
'form' => $form->createView(),
);
}
和表格
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('skill', 'text', array('label' => 'Skill Name', 'required' => false))
->add('mainSkill','checkbox',
array(
'label' => 'Select for Main Skill?',
'required' => false,)
);
$builder->add('language','entity',
array(
'class'=>'My\MyBundle\Entity\CodeDirectoryProgramLanguages',
'property'=>'languages',
'multiple'=>true,
'expanded' => true,
)
);
$builder
->add('edit','submit')
;
}
我的实体
class Skill
{
use Timestampable;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="main_skill", type="boolean", nullable=true)
*/
private $mainSkill;
/**
* @var \Artel\ProfileBundle\Entity\CodeDirectoryProgramLanguages
*
* @ORM\ManyToMany(targetEntity="CodeDirectoryProgramLanguages", inversedBy="skills", cascade={"persist"})
*/
protected $language;
和CodeDirectoryProgramLanguages
class CodeDirectoryProgramLanguages
{
use Timestampable;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="languages", type="string", length=255)
*/
private $languages;
/**
* @ORM\ManyToMany(targetEntity="Artel\ProfileBundle\Entity\Skill", mappedBy="language")
*/
protected $skills;
这是我的模板,非常简单
{% extends 'MyBundle:Dashboard:index.html.twig' %}
{% block form %}
{{ form(form) }}
{% endblock %}
解决 在行动中删除$ form-> submit($ request);并在post $ form-> bind($ request);
之后添加 if ($request->isMethod('POST')) {
$form->bind($request);
答案 0 :(得分:0)
也许您的ParamConverter无法正常工作并且无法返回正确的实体