测试树枝实体中是否存在方法
Test if a method exists in entity from twig
我想编辑默认表单模板以在显示上传字段时包含图像的缩略图预览,因此我在 returns 路径的实体中放置了一个名为 getFormThumbnail() 的方法。当实体有它工作的方法时,但当它没有时,我得到一个错误:
An exception has been thrown during the rendering of a template ("Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Acme\UserBundle\Entity\UserTranslation' does not have a method 'getFormThumbnail' in C:\...\symfony\vendor\knplabs\doctrine-behaviors\src\Knp\DoctrineBehaviors\Model\Translatable\TranslatableMethods.php line 140") in kernel.root_dir/Resources/views/Form/form_div_layout.html.twig at line 43.
500 Internal Server Error - Twig_Error_Runtime
我正在编辑 {% block form_widget_simple %}
中的代码
我补充说:
{% if type == 'file' %}
{% if form.vars.form.parent.vars.value.getFormThumbnail is not null %}
<img src="{{ form.vars.form.parent.vars.value.getFormThumbnail | imagine_filter('thumb_250') }}" style="display: block; margin-bottom: 10px">
{% endif %}
{% endif %}
当 getFormThumbnail 存在时,此代码完美运行。所以我尝试添加 is defined
但它不起作用,我什至尝试过类似的东西:
form is defined
and
form is not null
and
form.vars is defined
and
form.vars is not null
and
form.vars.form is defined
and
form.vars.form is not null
and
form.vars.form.parent is defined
and
form.vars.form.parent is not null
and
form.vars.form.parent.vars is defined
and
form.vars.form.parent.vars is not null
and
form.vars.form.parent.vars.value is defined
and
form.vars.form.parent.vars.value is not null
and
form.vars.form.parent.vars.value.getFormThumbnail is defined
and
form.vars.form.parent.vars.value.getFormThumbnail is not null
仍然,我总是得到同样的错误,顺便说一句,错误中的行是我测试是否定义了 getFormThumbnail 的行
所以如果错误是does not have a method
有没有办法测试它是否有方法?
我想编辑默认表单模板以在显示上传字段时包含图像的缩略图预览,因此我在 returns 路径的实体中放置了一个名为 getFormThumbnail() 的方法。当实体有它工作的方法时,但当它没有时,我得到一个错误:
An exception has been thrown during the rendering of a template ("Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Acme\UserBundle\Entity\UserTranslation' does not have a method 'getFormThumbnail' in C:\...\symfony\vendor\knplabs\doctrine-behaviors\src\Knp\DoctrineBehaviors\Model\Translatable\TranslatableMethods.php line 140") in kernel.root_dir/Resources/views/Form/form_div_layout.html.twig at line 43.
500 Internal Server Error - Twig_Error_Runtime
我正在编辑 {% block form_widget_simple %}
我补充说:
{% if type == 'file' %}
{% if form.vars.form.parent.vars.value.getFormThumbnail is not null %}
<img src="{{ form.vars.form.parent.vars.value.getFormThumbnail | imagine_filter('thumb_250') }}" style="display: block; margin-bottom: 10px">
{% endif %}
{% endif %}
当 getFormThumbnail 存在时,此代码完美运行。所以我尝试添加 is defined
但它不起作用,我什至尝试过类似的东西:
form is defined
and
form is not null
and
form.vars is defined
and
form.vars is not null
and
form.vars.form is defined
and
form.vars.form is not null
and
form.vars.form.parent is defined
and
form.vars.form.parent is not null
and
form.vars.form.parent.vars is defined
and
form.vars.form.parent.vars is not null
and
form.vars.form.parent.vars.value is defined
and
form.vars.form.parent.vars.value is not null
and
form.vars.form.parent.vars.value.getFormThumbnail is defined
and
form.vars.form.parent.vars.value.getFormThumbnail is not null
仍然,我总是得到同样的错误,顺便说一句,错误中的行是我测试是否定义了 getFormThumbnail 的行
所以如果错误是does not have a method
有没有办法测试它是否有方法?