用象征主义创造形式



我正努力让我的表单从两天开始工作。我在上下阅读Symfony书中的"表格"一章,但我不知道自己做错了什么。这是我的实体类:

/**
 * Homecontent
 *
 * @ORMTable(name="homecontent", indexes={@ORMIndex(name="id_idx", columns={"author_id"})})
 * @ORMEntity()
 */
class Homecontent
{
    /**
     * @var integer
     *
     * @ORMColumn(name="home_id", type="integer", nullable=false)
     * @ORMId
     * @ORMGeneratedValue(strategy="IDENTITY")
     */
    private $homeId;
    /**
     * @var DateTime
     *
     * @ORMColumn(name="date", type="datetime", nullable=false)
     */
    private $date;
    /**
     * @var string
     *
     * @ORMColumn(name="title", type="text", nullable=false)
     *
     */
    private $title;
    /**
     * @var string
     *
     * @ORMColumn(name="content", type="text", nullable=false)
     */
    private $content;
    /**
     * @var string
     *
     * @ORMColumn(name="picture_path", type="text", nullable=false)
     */
    private $picturePath;
    /**
     * @var Contentuser
     *
     * @ORMManyToOne(targetEntity="Contentuser")
     * @ORMJoinColumns({
     *   @ORMJoinColumn(name="author_id", referencedColumnName="content_user_id")
     * })
     */
    private $author;

这是我的控制器:

/**
     * @param $request
     * @return SymfonyComponentHttpFoundationResponse
     * @Route("/content/insert")
     */
    public function indexAction(Request $request)
    {
        $content = new HomecontentType();
        $form = $this->createForm(HomecontentType::class);
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()
                ->getManager();
            $em->persist($content);
            $em->flush();
            return $this->redirectToRoute('worked check index');
        }
        return $this->render('Form/ContentForm.html.twig', array('form' => $form->createView()));

这是我的Form Class:

/**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('title')
            ->add('content')
            ->add('picturePath')
            ->add('date',DateTimeType::class)
        ;
    }
    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'AppBundleEntityHomecontent'
        ));
    }
}

我使用树枝进行渲染,它正在工作,但当我想提交它时,我得到了一个错误

在链配置的命名空间AppBundle\Entity 中找不到类"AppBundle\Form\HomecontentType"

很抱歉代码部分太长。提前感谢!

indexAction的开头出现错误,正确的代码是:

$content = new Homecontent();
$form = $this->createForm(HomecontentType::class, $content);

相关内容

  • 没有找到相关文章

最新更新