Friends who are new to php. Everyone will want to find a framework that can be used quickly to learn to do projects. Generally speaking, I will choose ThinkPHP to try. This framework is not difficult to get started and can quickly develop an application. Suitable for small business applications. Because it was developed by Chinese people, Chinese support is better. There are relatively comprehensive documents, and the official website community is also relatively active. But at a certain stage, you are basically not satisfied with using ThinkPHP, and choose a high-performance development framework. Yii comes with a rich set of features, including MVC, DAO/ActiveRecord, I18N/L10N, caching, authentication and role-based access control, scaffolding, testing, etc., which can significantly shorten development time. Here our PHP Chinese website will take you to learn how to create forms using the yii2 framework from scratch.First of all, you can go to our php Chinese website to watch online
You can also go to
##php Chinese website download siteDownload:Yii2 Chinese Manual
Let’s get to the point of creating the form in the yii2 framework:
Directory
Generation of form
Methods in the formActiveForm::begin() method
ActiveForm::end() methodgetClientOptions() method
Other methods: errorSummary, validate, validateMultiple
Parameters in the form
Itself attributes
Attributes related to each item (field) input box in the form$fieldConfigAbout the attributes of validation
About the attributes of each field container style
Ajax validation
Front-end js event
Other attributes in the form
Let’s take a look at Yii first It contains the simplest login form and the generated html code and interface. Let’s have an intuitive understanding first.
'login-form']); ?> = $form->field($model, 'username') ?> = $form->field($model, 'password')->passwordInput() ?> = $form->field($model, 'rememberMe')->checkbox() ?>The following is the generated form Html. I have marked 5 parts in it.If you forgot your password you can = Html::a('reset it', ['site/request-password-reset']) ?>
= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
1. Form generation
In Yii, the form is both ActiveForm and Widget. As you can see above, it starts with begin
'login-form']); ?>The middle is The input box of each item ends with end
2. Methods in the form
The begin() method in Widget will call the int method
public function init()The run method will be called in the final end() method
public function run()
1. ActiveForm::begin() method
//这个是在执行 $form = ActiveForm::begin(['id' => 'login-form']); 中的begin方法的时候调用的 public function init() { //设置表单元素form的id if (!isset($this->options['id'])) { $this->options['id'] = $this->getId(); } //设置表单中间的要生成各个field的所使用的类 if (!isset($this->fieldConfig['class'])) { $this->fieldConfig['class'] = ActiveField::className(); } //这个就是输出表单的开始标签 //如: