我收到错误"试图调用方法" generateUrl"上课#34; Symfony 2.6

时间:2016-02-15 09:51:47

标签: php forms symfony crud

在生成角色CRUD( 控制台生成:doctrine:crud )之后,我尝试使用RoleType覆盖Form,

但我得到错误:
 Attempted to call method "generateUrl" on class "BISSAP\UserBundle\Form\RoleType".

CRUD的一部分 - RoleController.php

public function newAction()
    {
        $entity = new Role();
        //$form   = $this->createCreateForm($entity);
        $form   = $this->createForm(new RoleType(),$entity, array(
            'action' => $this->generateUrl('role_create'),
            'method' => 'POST',
        ));

        return $this->render('BISSAPUserBundle:Role:new.html.twig', array(
            'entity' => $entity,
            'form'   => $form->createView(),
        ));
    }

路由的一部分 - role.yml

role_new:
    path:     /new
    defaults: { _controller: "BISSAPUserBundle:Role:new" }

role_create:
    path:     /create
    defaults: { _controller: "BISSAPUserBundle:Role:create" }
    requirements: { _method: post }

RoleType.php

的一部分
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('role')
            ->add('description')
            ->add('groupRole',
                      'entity',
                       array(
                             'class'=>'BISSAP\UserBundle\Entity\GroupRole',
                             'property'=>'name',
                             'query_builder' => function (\BISSAP\USerBundle\Entity\GroupRoleRepository $repository)
                             {
                                 return $repository->createQueryBuilder('c');
                                        //->where('c.parent = :parent')
                                        //->setParameter('parent', 19)
                                        //->add('c.name', 'ASC');
                             }
                            )
                      )
            ->add('Enregistrer', 'submit', array(
                'attr' => array(
                'class' => 'blabla')));
            //->add('groupRole');

    }

所以,我不明白,为什么generateUrl不起作用?!

1 个答案:

答案 0 :(得分:1)

真奇怪!似乎RoleType代表RoleController实例,而不代表public function newAction() { $entity = new Role(); $url = $this->generateUrl('role_create'); $form = $this->createForm(new RoleType(), $entity, array( 'action' => $url, 'method' => 'POST', )); return $this->render('BISSAPUserBundle:Role:new.html.twig', array( 'entity' => $entity, 'form' => $form->createView(), )); }

试试这个:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

//Does not support mobile
[RequireComponent(typeof(AudioSource))]
public class Movie : MonoBehaviour
{
        public bool playOnStart = true;
        #if !(UNITY_ANDROID || UNITY_IPHONE) || UNITY_EDITOR
        public MovieTexture movieTexture;
        #endif

        public AudioSource audioSource;

        IEnumerator Start ()
        {
                if (audioSource == null) {
                        audioSource = GetComponent<AudioSource> ();
                }

                audioSource.Stop ();
                if (playOnStart) {
                        Play ();
                }
            yield return 0;
        }

        /// <summary>
        /// Play the movie
        /// </summary>
        public void Play ()
        {
            #if !(UNITY_ANDROID || UNITY_IPHONE) || UNITY_EDITOR
                if(movieTexture == null){
                    Debug.Log("Movie texture is undefined");
                    return;
                }
                GetComponent<RawImage>().enabled = true;
                GetComponent<RawImage>().texture = movieTexture;
                movieTexture.Play ();
                audioSource.clip = movieTexture.audioClip;
                audioSource.Play ();

            #endif
        }
}