2017-07-11 8 views
0

Yii2フレームワークを使用してビューにチェックボックスを追加したいと思います。 HTML、JavaScript、Angularを使用するのはとても簡単ですが、Yii2で行う方法はわかりません。Yii:ビューに単純なチェックボックスを追加する方法

<div class="col-md-6"> 
    <?= $form->field($model, 'username')->textInput(['maxlength' => true]) ?> 
</div> 

そして今、私は、チェックボックスを必要とする:

は、私は、ビュー内のユーザー名の入力が_form.phpと呼ばれています。

すべてのコンポーネントを示す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', 
     ]; 
    } 
} 

ので属性は以下のとおりです。ユーザ名、ステータス、AUTH_KEY、電子メールやpassword_reset_token。しかし、私は人口という新しい属性を使用したいが、私はそれを行う方法を知らない。

答えて

1

利用->checkBoxの代わりにtextInput

<div class="col-md-6"> 
    <?= $form->field($model, 'username')->checkBox(['label' => 'your_label']) ?> 
</div> 

http://www.bsourcecode.com/yiiframework2/yii2-0-activeform-input-fields/

http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html

http://www.yiiframework.com/doc-2.0/guide-helper-html.html

+0

私はフィールド($モデル、 '人口')を使用 - >チェックボックス(); ?>しかし、私は "不明なプロパティを取得しています:app \ models \ User :: population"というエラーが表示されます。 –

+0

あなたのUserモデルに属性の人口がないようです... – scaisEdge

関連する問題