如何在Zend框架2使用Zend从添加自定义属性 [英] How add custom attribute in zend framework 2 using zend from

查看:161
本文介绍了如何在Zend框架2使用Zend从添加自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Zend框架项目,在这个项目形式使用Zend形式生成使用angularJS。如何添加角指令,例如在表单元素NG-模式,但每当我试图在Zend形式元素添加这个自定义属性(输入选择等),鉴于我没有得到这个属性--- -

I want to use angularJS in a zend framework project and in this project forms are generated using zend form. How can I add angular directive such as "ng-model" in the form elements but whenever i was trying to add this custom attribute in the zend-form elements (input, select etc) in view I am not getting this attribute ----

下面是我的领导形式

类LeadForm扩展表格{

class LeadForm extends Form {

public function __construct() {

    parent::__construct('lead_form');

    $this->setAttributes(array(
        'action' => '',
        'method' => 'post',
        'name' => 'lead_form',
        'id' => 'lead_form',
        'class' => 'smart-form',
        'role' => 'form',
        'novalidate' => 'novalidate'
    ));

    $this->add(array(
        'name' => 'first_name',
        'type' => 'text',
        'options' => array(
            'label' => 'First Name',
        ),
        'attributes' => array(
            'class' => 'form-control validate[required,custom[onlyLetterSp]]',                
            'placeholder' => 'First name',                
            **'ng-model' => "first_name", // this attribute is not generating in view**
        ),            
    ));
}

}

下面是我的控制器,它是调用此表格并发送,查看显示

Here is my controller which is calling this form and send to view for displaying

$createLeadForm = new \Admin\Form\LeadForm();

return new ViewModel(array(
            'form' => $createLeadForm,
));

下面是针对我的code为显示单元

Here is my code in view for showing element

<?php echo $this->formInput($this->form->get('first_name')); ?>

但是prinnting这种形式的因素我得到看到输入元素没有NG-模式之后

<input type="text" value="" placeholder="First name" class="form-control validate[required,custom[onlyLetterSp]]" name="first_name" >

我已经设置一个属性NG-模式,但是这个属性并不在视图中出现的

我想这个元素像(使用Zend形式) -

<input type="text" ng-model="first_name" value="" placeholder="First name" class="form-control validate[required,custom[onlyLetterSp]]" name="first_name" >

我怎么能做到这一点使用Zend形式,哪些需要以这种形式改变,我为什么不能添加自定义属性?请帮助我。

How can I do that using zend form and what need to change in this form and why i can not able to add custom attribute? please help me.

由于提前

推荐答案

您可以随时使用数据纳克 - *:

You always can use data-ng-*:

$this->add(array(
    // ...
    'attributes' => array(
        // ...
        'data-ng-model' => 'first_name',
    ),            
));

这篇关于如何在Zend框架2使用Zend从添加自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆