【发布时间】:2017-07-31 20:51:35
【问题描述】:
我想使用 Yii2 框架为视图添加一个复选框。 使用 HTML、JavaScript 或 Angular 很容易,但我不明白如何使用 Yii2。
我在名为 _form.php 的视图中有一个用户名输入:
<div class="col-md-6">
<?= $form->field($model, 'username')->textInput(['maxlength' => true]) ?>
</div>
现在我需要一个复选框。
是否有任何 Yii 文档显示其所有组件?
这是我的模型:
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "user".
*
* @property integer $id
* @property string $username
* @property string $auth_key
* @property string $password_hash
* @property string $password_reset_token
* @property string $email
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
*/
class User extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'user';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'auth_key', 'password_hash', 'email', 'created_at', 'updated_at'], 'required'],
[['status', 'created_at', 'updated_at'], 'date','format' => 'd-M-yyyy H:m'],
[['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
[['auth_key'], 'string', 'max' => 32],
[['email'], 'unique'],
[['password_reset_token'], 'unique'],
[['username'], 'unique'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'Idadm',
'username' => 'Nombre de usuario',
'auth_key' => 'Auth Key',
'password_hash' => 'Password Hash',
'password_reset_token' => 'Password Reset Token',
'email' => 'Email',
'status' => 'Status',
'created_at' => 'Creado',
'updated_at' => 'Actualizado',
];
}
}
所以属性是:username、status、auth_key、email 和password_reset_token。但我想使用一个名为 population 的新属性,但我不知道该怎么做。
【问题讨论】:
标签: php html checkbox yii2 yii2-advanced-app