Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 - createForm called with custom form type's name/alias throws "Could not load type" exception
    primarykey
    data
    text
    <p>I was reading the documentation on defining forms as services and followed the guide. but I keep running into the following error:</p> <blockquote> <p>Could not load type "submission"</p> </blockquote> <p>here is my <code>services.yml</code></p> <pre><code>services: submission.form.type.submission: class:Awesome\SubmissionBundle\Form\Type\SubmissionType tags: - {name: form.type, alias: submission} </code></pre> <p>here is my form</p> <pre><code>&lt;?php namespace Awesome\SubmissionBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class SubmissionType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder -&gt;add('contact', 'text') -&gt;add('message', 'textarea') -&gt;add('submit', 'submit') ; } public function getName() { return 'submission'; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver-&gt;setDefaults(array( 'data_class' =&gt; 'Awesome\SubmissionBundle\Entity\Submission', )); } } </code></pre> <p>In any controller I can <code>$this-&gt;get('submission.form.type.submission')</code> without errors.</p> <p><strong>But why can't I do <code>$this-&gt;createForm('submission', $submission)</code></strong> ? as is dictated by the official <a href="http://symfony.com/doc/current/book/forms.html#defining-your-forms-as-services" rel="nofollow">documentation</a>.</p> <p><strong>UPDATE</strong> I have made some progress. I found that if I put my services configuration in symfony's main <code>config.yml</code> rather than the bundles <code>services.yml</code> The code starts to work. This is perplexing but I guess it leads to me posting just how I'm loading the bundle's <code>services.yml</code>.</p> <p>Here is my bundle's registered compiler pass:</p> <pre><code>&lt;?php namespace Awesome\SubmissionBundle\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; class SubmissionCompilerPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { $relative_path = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('..', '..', 'Resources', 'config')); $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . $relative_path)); $loader-&gt;load('services.yml'); } } </code></pre> <p>and regardless of where I place my configuration the command <code>container:debug submission.form.type.submission</code> always gives the same output which seems fine to me:</p> <pre><code>[container] Information for service submission.form.type.submission Service Id submission.form.type.submission Class Awesome\SubmissionBundle\Form\Type\SubmissionType Tags - form.type (alias: submission) Scope container Public yes Synthetic no Required File - </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload