Yii-gii-creating-model

提供:Dev Guides
移動先:案内検索

Gii-モデルの作成

Giiでモデルを作成するには-

<?php
   namespace app\models;
   use app\components\UppercaseBehavior;
   use Yii;
  /**
 *This is the model class for table "user".
  *
 *@property integer $id
  * @property string $name
 *@property string $email
  */
   class MyUser extends \yii\db\ActiveRecord {
     /**
 *@inheritdoc
     */
      public static function tableName() {
         return 'user';
      }
     /**
 *@inheritdoc
     */
      public function rules() {
         return [
            [[name', 'email'], 'string', 'max' => 255]
         ];
      }
     /**
 *@inheritdoc
     */
      public function attributeLabels() {
         return [
            'id' => 'ID',
            'name' => 'Name',
            'email' => 'Email',
         ];
      }
   }
?>

CRUDの生成

MyUserモデルのCRUDを生成します。

  • ステップ1 *-CRUDジェネレーターインターフェイスを開き、フォームに入力します。

Crud Generator Interface

ステップ2 *-次に、[プレビュー]ボタンをクリックして[生成]をクリックします。 URL *http://localhost:8080/index.php?r = my-user にアクセスすると、すべてのユーザーのリストが表示されます。

プレビューボタンをクリック

ステップ3 *-URL *http://localhost:8080/index.php?r = my-user/create を開きます。 ユーザー作成フォームが表示されます。

ユーザー作成フォーム