Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony 2.7.7-表格收集“;注意:未定义索引:pageId";_Php_Symfony_Doctrine Orm_Symfony Forms - Fatal编程技术网

Php Symfony 2.7.7-表格收集“;注意:未定义索引:pageId";

Php Symfony 2.7.7-表格收集“;注意:未定义索引:pageId";,php,symfony,doctrine-orm,symfony-forms,Php,Symfony,Doctrine Orm,Symfony Forms,试图生成一个表单,在其中它将是一个内容的集合,但不幸地失去了她的错误,不知道我们如何恢复 给我错误信息 注意:未定义索引:pageId 500内部服务器错误-ContextErrorException 页面实体: class Page { private $id; private $name; /** * @ORM\OneToMany(targetEntity = "PageContent", mappedBy = "pageId&

试图生成一个表单,在其中它将是一个内容的集合,但不幸地失去了她的错误,不知道我们如何恢复

给我错误信息

注意:未定义索引:pageId

500内部服务器错误-ContextErrorException

页面实体:

class Page
{
    private $id;
    private $name;
    /**
     * @ORM\OneToMany(targetEntity = "PageContent", mappedBy = "pageId")
     */
    private $content;
}
页面内容实体:

class PageContent
{
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity = "Page", inversedBy = "page_content")
     * @ORM\JoinColumn(name = "page_id", referencedColumnName = "id", onDelete = "SET NULL")
     */
    private $page;
    private $name;
}
EditPageContentsType:

<?php
namespace Eteam\SettingsBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class EditPageContentsType extends AbstractType
{
    /**
     * Returns the name of this type.
     *
     * @return string The name of this type
     */
    public function getName()
    {
        return 'EditPageContents';
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('pageContentMap')
            ->add('content', 'collection', array(
                'type' => new PageContentType(),
                'options'  => array(
                    'required'  => false
                ),
                'allow_add' => true
            ));

    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Eteam\PageBundle\Entity\Page',
        ));
    }
}

首先,您的注释是错误的

第页应为:

 * @ORM\OneToMany(targetEntity = "PageContent", mappedBy = "page")
 * @ORM\ManyToOne(targetEntity = "Page", inversedBy = "content")
页面内容应为:

 * @ORM\OneToMany(targetEntity = "PageContent", mappedBy = "page")
 * @ORM\ManyToOne(targetEntity = "Page", inversedBy = "content")
mappedBy和inversedBy与关系对象的属性名称直接相关,并且必须相同

其次,由于PageContent是Page的子级,所以PageContentType中不需要pageId。这是一种更好的做事方式

在EditPageContentsType中,添加选项
'by_reference'=>false

然后更改页面中的addContent()方法

public function addContent(PageContent $pageContent)
{
    $pageContent->setPage($this);

    $this->content->add($pageContent);
}
与addTag示例类似,只需稍微向下一点


这使您可以轻松地将页面与页面内容实体相关联。我建议您好好阅读一下,因为您会经常看到这种情况。

非常感谢。我还有一个问题,这已经是一个表格了。页面内容包括:名称类型编辑形式的内容仅为内容,“名称”是“类型”输入的名称此类输入如“文本”或“文本区域”。我的问题是:如何将这些信息注入表单?为什么需要存储内容类型?如果是在内容创建时,您可以将类型设置为选择字段。另外,如果我的原始答案对您有所帮助,请将其标记为有用。谢谢。当我有足够的信誉点时,我肯定会。你看,这一点是,这些字段是不可编辑的,只有内容、类型和名称仅供参考,并作为表单中的设置字段。例如:名称:标题类型:文本内容:要填充的位置,名称:文章类型:文本区域内容:要填充的位置,依此类推。如果你有一个想法,我会非常感激,因为我不再完全不知道它是如何跳过的。