Can anyone explain why this code:
{% form_theme form _self %}
{% block avo_gallery_upload_widget %}
{% spaceless %}
<label for="name">Name:</label>
{{ form_widget(form.name) }}
<label for="description">Description:</label>
{{ form_widget(form.description) }}
{% endspaceless %}
{% endblock avo_gallery_upload_widget %}
Throws
Method "name" for object "Symfony\Component\Form\FormView" does not exist in MyBundle:Default:upload.html.twig at line 13
For reference: line 13 is {{ form_widget(form.name) }}
But when wrapped in IF clause:
{% form_theme form _self %}
{% block avo_gallery_upload_widget %}
{% spaceless %}
{% if form.name is defined %}
<label for="name">Name:</label>
{{ form_widget(form.name) }}
<label for="description">Description:</label>
{{ form_widget(form.description) }}
{% endif %}
{% endspaceless %}
{% endblock avo_gallery_upload_widget %}
Suddenly everything works fine!
For reference – this is how form looks like:
class GalleryUploadType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('name', 'text')
->add('description', 'textarea')
;
}
public function getName()
{
return 'avo_gallery_upload';
}
public function getDefaultOptions(array $options){
return array('data_class' => 'Me\MyBundle\Entity\GalleryUpload');
}
}
fabpot closed github issue (2012-07-03) with comment:
Since it probably is something wrong in my application and there is nothing new I could add to the question I am closeing this question.
If you happen to encounter this error have a look at this workaround.
If you have any additional info on reproducing the problem, post it here.