Md.*_*lam 2 php custom-attributes zend-form zend-framework2 angularjs
我想在zend框架项目中使用angularJS,在这个项目中,表单是使用zend形式生成的.如何在表单元素中添加角度指令,如"ng-model",但每当我尝试在zend-form元素中添加此自定义属性(输入,选择等)时,我都没有得到这个属性--- -
这是我的主要形式
class LeadForm扩展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**
),
));
}
Run Code Online (Sandbox Code Playgroud)
}
这是我的控制器,它调用此表单并发送到视图进行显示
$createLeadForm = new \Admin\Form\LeadForm();
return new ViewModel(array(
'form' => $createLeadForm,
));
Run Code Online (Sandbox Code Playgroud)
这是我的代码,用于显示元素
<?php echo $this->formInput($this->form->get('first_name')); ?>
Run Code Online (Sandbox Code Playgroud)
但在打开这个表单元素后,我在输入元素中看不到"ng-model"
<input type="text" value="" placeholder="First name" class="form-control validate[required,custom[onlyLetterSp]]" name="first_name" >
Run Code Online (Sandbox Code Playgroud)
我设置了一个属性"ng-model",但该属性没有出现在视图中
我想要这个元素(使用zend形式) -
<input type="text" ng-model="first_name" value="" placeholder="First name" class="form-control validate[required,custom[onlyLetterSp]]" name="first_name" >
Run Code Online (Sandbox Code Playgroud)
如何使用zend表单以及需要在此表单中更改的内容以及为什么我无法添加自定义属性?请帮我.
提前致谢
小智 5
你总是可以使用数据-ng-*:
$this->add(array(
// ...
'attributes' => array(
// ...
'data-ng-model' => 'first_name',
),
));
Run Code Online (Sandbox Code Playgroud)