Home > PHP Framework > YII > body text

How to write a yii framework form?

angryTom
Release: 2020-02-05 17:59:14
Original
1711 people have browsed it

In Yii, forms (form widgets) are mainly created through the yii\widgets\ActiveForm class. Let's introduce how to write forms in yii. We hope it will be helpful to students who are learning the yii framework!

How to write a yii framework form?

How to write a yii framework form?

(1) First create a form instance

<?php $form=ActiveForm::begin();?> //$form是表单实例
...
<?php ActiveForm::end();?>
Copy after login

ActiveForm::begin() not only marks the start of the form, but also creates a form instance.

Recommended learning: yii tutorial

(2) Then create an ActiveField instance

  <?php $form=ActiveForm::begin();?>
+  <?= $form->field($model,&#39;title&#39;)?>
  <?php ActiveForm::end();?>
Copy after login

and place it in ActiveForm: Everything between :begin() and ActiveForm::end() is wrapped in the HTML

tag.

Create an ActiveField instance by calling the ActiveForm::field() method. This instance will create the form element and the element's label, as well as the corresponding JavaScript response.

Each ActiveField has a corresponding model and attribute. The name attribute of the input input box will be automatically created based on the attribute name; at the same time, the attribute verification rules will be used to verify the user's data input.

(3) Create an ActiveField object using the example

<?= $form->field($model,&#39;body&#39;)->textarea([&#39;rows&#39;=>3]) =?>
Copy after login
  • $form->field($model,'body');

  • ActiveField's method textarea() creates a 3-line input box;

The above is the detailed content of How to write a yii framework form?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template