【问题标题】:How can i make a read only field on zend framework如何在 zend 框架上创建只读字段
【发布时间】:2015-04-30 11:22:49
【问题描述】:

我有这个字段

$mobile = new Zend_Form_Element_Textarea('mobile');
    $mobile->setLabel('mobile')
    ->addFilter('StripTags')
    ->addFilter('StringTrim')
    ->setOptions(array('class' => 'full-width'))
    ->setAttrib('rows', 2)
    ->getDecorator(('label'))->setOption('tag', 'span');
    $this->addElement($phone);

但我需要只读但我会在数据表中添加内容

【问题讨论】:

    标签: php database zend-framework model-view-controller zend-form


    【解决方案1】:

    您可以使用setAttrib 方法设置任何属性。

    ->setAttrib('readonly', 'true');
    

    【讨论】:

    • 谢谢@s-rupali,但是当我使用此 setAttrib('readonly','true') 进行更新时,我可以更新我的数据库中的数据,提前谢谢
    • 能否请您也用数据库代码更新您的问题?
    【解决方案2】:

    setOptions 将设置字段的属性。也只需传递readonly。试试 -

    ->setOptions(array('class' => 'full-width', 'readonly' => true))
    

    【讨论】:

    • 感谢@sgt BOSE,但是当我使用此 setAttrib('readonly','true') 进行更新时,我可以更新我的数据库中的数据,提前谢谢
    • 我想用这个字段属性只读更新数据库
    • 应该这样做。有什么问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-01
    • 1970-01-01
    • 2019-04-16
    相关资源
    最近更新 更多