加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Symfony2,如何在表单中添加隐藏日期类型字段?

发布时间:2020-12-13 22:19:59 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试下面的场景: 在myclassType中 public function buildForm(FormBuilder $builder,array $options){ $builder -add('day','hidden') -add('date','hidden' ) -add('hours') -add('comment','textarea') ;} 在myclass中 class myclass{ //.. Other s
我正在尝试下面的场景:

在myclassType中

public function buildForm(FormBuilder $builder,array $options)
{
    $builder
        ->add('day','hidden')
        ->add('date','hidden' ) 
        ->add('hours')
        ->add('comment','textarea')
    ;
}

在myclass中

class myclass
{
    //.. Other stuff

    /**
     * @ORMColumn(type="date")
     *
     * @var date $date
     */
    protected $date;
}

渲染时我收到此错误:

An exception has been thrown during the rendering of a template ("Catchable Fatal Error:
 Object of class DateTime could not be converted to string in 
C:wampwwwPMI_sf2appcachedevtwigfb408957f80f2358a6f4112c3427b387.php line 684") in
 form_div_layout.html.twig at line 171.

知道我怎么能隐藏日期类型字段!??

解决方法

形成

$builder
    ->add('day','hidden')
    ->add('date',null,array( 'attr'=>array('style'=>'display:none;')) )
...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读