Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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 Symfony2(beta5)1:M/M:1格式_Php_Symfony_Doctrine Orm - Fatal编程技术网

Php Symfony2(beta5)1:M/M:1格式

Php Symfony2(beta5)1:M/M:1格式,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,我有实体“创造性”和实体“问题”。。。当我有一个从创意到问题的多个关系时,我可以很容易地做$builder->add('questions'),它会抓住所有的问题,将它们放在一个多选中并插入到创意问题中。嗯,我需要一个新的领域(职位)来解决创造性的问题,所以我必须建立一个“一人一人”的关系。但是当我添加字段($builder->add('creativeQuestions'))时,multi-select是空的,它似乎试图查询creative_问题来填充它。。这是错误的。我需要填充问题,并将其插

我有实体“创造性”和实体“问题”。。。当我有一个从创意到问题的多个关系时,我可以很容易地做$builder->add('questions'),它会抓住所有的问题,将它们放在一个多选中并插入到创意问题中。嗯,我需要一个新的领域(职位)来解决创造性的问题,所以我必须建立一个“一人一人”的关系。但是当我添加字段($builder->add('creativeQuestions'))时,multi-select是空的,它似乎试图查询creative_问题来填充它。。这是错误的。我需要填充问题,并将其插入到创造性问题中

无论如何,这是我的代码:

## Creative.php

[...]

/**
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
protected $id;

/**
 * @ORM\ManyToOne(targetEntity="Offer", cascade={"persist"})
 */
protected $offer;

/**
 * @ORM\OneToMany(targetEntity="CreativeQuestion", mappedBy="creative", cascade={"persist"})
 */
protected $creativeQuestions;

[...]



同样,当我删除CreativeQuestion,只做一个有很多关系的问题时,我需要的工作是:

但是,理想情况下,我希望能够(使用jquery)通过从下拉框中选择来添加问题,然后通过拖放来定位问题。jquery的定位很简单,我只是不知道如何添加我想添加的问题。如果我至少可以让multiselect工作,那么我可以继续前进,但我现在有点被卡住了

有人用Symfony2(beta5)达到这一步了吗

## CreativeQuestion.php

[...]

/**
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
protected $id;

/**
 * @ORM\ManyToOne(targetEntity="Creative", cascade={"persist"})
 */
protected $creative;

/**
 * @ORM\ManyToOne(targetEntity="Question", cascade={"persist"})
 */
protected $question;

/**
 * @ORM\Column(type="integer")
 */
protected $pos;

[...]
## CreativeType.php

[...]

public function buildForm(FormBuilder $builder, array $options)
{
    $builder
        ->add('name')
        ->add('title')
        ->add('description')
        ->add('body')
        ->add('script')
        ->add('creativeQuestions') // how do i populate list with "Questions" then insert into creative_question?
        ->add('active');
}

public function getDefaultOptions(array $options)
{
    return array(
        'data_class' => 'JStout\MainBundle\Entity\Creative'
    );
}

[...]
## In My Controller:

 /**
 * @Extra\Route("/offer/{offerId}/creative", name="admin_offer_creative")
 * @Extra\Route("/offer/{offerId}/creative/{creativeId}", name="admin_offer_creative_edit")
 * @Extra\Template()
 */
public function creativeAction($offerId = null, $creativeId = null)
{
    // Get Offer
    $offer = $this->_getObject('Offer', $offerId);

    if (null === $offer->getId()) throw new NotFoundHttpException('The page you requested does not exist!');

    // Get Creative
    $creative = $this->_getObject('Creative', $creativeId);

    // Set offer to creative
    $creative->setOffer($offer);

    // Get form and handler
    $form = $this->get('form.factory')->create(new Form\CreativeType(), $creative);
    $formHandler = $this->get('form.handler')->create(new Form\CreativeHandler(), $form);

    [...]
}

protected function _getObject($entityName, $id = null)
{
    // Find object
    if (null !== $id) {
        if (!$object = $this->get('doctrine')->getEntityManager()->find('ZGOffersMainBundle:' . $entityName, $id)) {
            throw new NotFoundHttpException('The page you requested does not exist!');
        }

        return $object;
    }

    // Initialize new object
    $entityName = 'JStout\MainBundle\Entity\\' . $entityName;
    if (class_exists($entityName)) {
        return new $entityName();
    }

    throw new NotFoundHttpException('The page you requested does not exist!');
}

[...]