doujia7094 2012-10-29 15:49
浏览 31

symfony2形成隐藏行

I'm trying to put two hidden fields in a form for a particular user. I have this code:

<div id="mio_miobundle_empleadotype">
{{ form_row(edit_form.dni) }}
{{ form_row(edit_form.nombre) }}
{{ form_row(edit_form.username) }}
{{ form_row(edit_form.apellido1) }}
{{ form_row(edit_form.apellido2) }}
{{ form_row(edit_form.localidad) }}
{{ form_row(edit_form.provincia) }}
{{ form_row(edit_form.telefono) }}
{{ form_row(edit_form.movil) }}
{{ form_row(edit_form.email) }}
{{ form_row(edit_form.direccion) }}
{% if is_granted('ROLE_A') %}     
      {{ form_row(edit_form.activo) }}
      {{ form_row(edit_form.role) }}
{%endif%}
{{ form_row(edit_form.password) }}

and:

$builder
            ->add('dni','text',array('label' => 'Dni'))
            ->add('nombre','text',array('label' => 'Nombre'))
            ->add('username','text',array('label' => 'Usuario'))
            ->add('apellido1','text',array('label' => 'Apellido1'))
            ->add('apellido2','text',array('label' => 'Apellido2'))
            ->add('email','email',array('label' => 'Email'))
            ->add('localidad','text',array('label' => 'Localidad'))
            ->add('provincia','text',array('label' => 'Provincia'))
            ->add('telefono','text',array('label' => 'Teléfono'))
            ->add('movil','text',array('label' => 'Móvil'))
            ->add('direccion','text',array('label' => 'Dirección'))
            ->add('activo')
            ->add('role')
            ->add('password', 'repeated', array('first_name' => 'Nueva contraseña','second_name' => 'Repite contraseña','type' => 'password' ,'invalid_message'=> 'Las contraseñas deben ser iguales.'))
        ;
    }

but I get this error:

Catchable Fatal Error: Argument 1 passed to mio\mioBundle\Entity\Empleado::setRole() must be an instance of mio\mioBundle\Entity\Role, null given, called in /var/www/Symfony/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 347 and defined in /var/www/Symfony/src/mio/mioBundle/Entity/Empleado.php line 289

I say that because I have to fill in the state are any help?

  • 写回答

2条回答 默认 最新

  • dragon4808 2012-10-29 16:52
    关注

    Instead of not rendering the fields completely, try hiding the fields from view using css.

    {% if is_granted('ROLE_A') %}     
          {{ form_row(edit_form.activo) }}
          {{ form_row(edit_form.role) }}
    {% else %}
          {{ form_widget(edit_form.activo, { 'attr': {'class': 'hide'} }) }}
          {{ form_widget(edit_form.role, { 'attr': {'class': 'hide'} }) }}
    {% endif %}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入