dotelauv682684
2017-03-30 06:19
浏览 70
已采纳

Symfony 3.2 FOSMessageBundle'... / new'(即撰写新消息)无论我做什么都会抛出错误

I'm not using FOSUserBundle (there's custom user/security code already in place). I've been following the docs here.

After much googling and digging through both Symfony and FOSMessageBundle files, I've come to believe that the issue has something to do with the new NewThreadMessageFormFactory class. It only has one method. If I leave it as is like so

    public function create()
    {
        return $this->formFactory->createNamed(
          $this->formName, 
          $this->formType, 
          $this->createModelInstance());
    }

I get this error Expected argument of type "string", "AppBundle\Service\NewThreadMessageFormType" given. On the other hand, if I do the following,

public function create()
{
    return $this->formFactory->createNamed(
      $this->formName,
      'AppBundle\Service\NewThreadMessageFormType', 
      $this->createModelInstance());
}

I get this Could not load type "FOS\UserBundle\Form\Type\UsernameFormType. Which, of course, doesn't even exist because FOSUserBundle isn't even installed.

I've already spent more than a dozen hours on this. I've learned a lot in the process, but I still can't make the darn thing work...


And my current configuration

//config.yml
fos_message:
    db_driver: orm
    thread_class: AppBundle\Entity\Thread
    message_class: AppBundle\Entity\Message
    new_thread_form:
        type: app.new_thread_form_type
        factory: app.new_thread_form_factory

and...

  //services.yml
  fos_user.user_to_username_transformer:
      alias: app.user_to_username_transformer

  app.user_to_username_transformer:
      class: AppBundle\Form\DataTransformer\UserToUsernameTransformer
      arguments:
          type: "service"
          id: "doctrine"

  app.new_thread_form_type:
      class: AppBundle\Service\NewThreadMessageFormType
      arguments: ['@app.user_to_username_transformer']
      tags:
          - {name: form.type}

  app.new_thread_form_factory:
      class: AppBundle\Service\NewThreadMessageFormFactory
      arguments: [
          '@form.factory',
          '@fos_message.new_thread_form.type',
          '%fos_message.new_thread_form.name%',
          '%fos_message.new_thread_form.model%'
          ]

1条回答 默认 最新

相关推荐 更多相似问题