Gii – Creating a Model


Gii – Creating a Model


”;


To create a Model in Gii −

<?php
   namespace appmodels;
   use appcomponentsUppercaseBehavior;
   use Yii;
   /**
   * This is the model class for table "user".
   *
   * @property integer $id
   * @property string $name
   * @property string $email
   */
   class MyUser extends yiidbActiveRecord {
      /**
      * @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'',
         ];
      }
   }
?>

Generating CRUD

Let us generate CRUD for the MyUser model.

Step 1 − Open the CRUD generator interface, fill in the form.

Crud Generator Interface

Step 2 − Then, click the “Preview” button and “Generate”. Go to the URL http://localhost:8080/index.php?r=my-user, you will see the list of all users.

Click Preview Button

Step 3 − Open the URL http://localhost:8080/index.php?r=my-user/create. You should see a user create form.

User Create Form

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *