小编Alb*_*lla的帖子

Symfony2表单:创建新的或选择现有的

我和实体A将oneToMany与实体B联系起来.我希望用户可以选择从现有的B实体中选择或者在A类的形式上创建一个新的实体.到目前为止,我在我的表单上有这个:

->add('ExistingB', 'entity', array(
            'class' => 'AppBundle\Entity\B',
            'required'    => false,
            'property_path' => 'B',
            'mapped' => false,
        ))

 ->add('newB',  new BType(), array(
            'required'    => false,
            'property_path' => 'B',
            'mapped' => false,
        ));

 $builder->addEventListener(
     FormEvents::POST_SUBMIT , function (FormEvent $event) {
          $formB= $event->getForm()->get('newB');

         if ($formB->get('name')->getData() != null){
                 //here i need to somehow say to the form that it needs to set mapped true 
                //to the formB field so it can create a new entity and update the relationship
         }else{
                  //here I need to …
Run Code Online (Sandbox Code Playgroud)

forms symfony

3
推荐指数
1
解决办法
1281
查看次数

为什么刚刚定义的数组count = 1?

对不起,我是重复的,但我似乎没有找到我需要澄清的确切方案.

所以我的问题是为什么:

var = array ();
echo count (var);
Run Code Online (Sandbox Code Playgroud)

打印0.

还有这个:

var = array (array());
echo count (var);
Run Code Online (Sandbox Code Playgroud)

打印1?

谢谢!

php

2
推荐指数
1
解决办法
47
查看次数

标签 统计

forms ×1

php ×1

symfony ×1