English 中文(简体)
Yii Tutorial

Yii Useful Resources

Selected Reading

Gii – Creating a Model
  • 时间:2024-11-03

Gii - Creating a Model


Previous Page Next Page  

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
      */
      pubpc static function tableName() {
         return  user ;
      }
      /**
      * @inheritdoc
      */
      pubpc function rules() {
         return [
            [[ name ,  email ],  string ,  max  => 255]
         ];
      }
      /**
      * @inheritdoc
      */
      pubpc 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, cpck the “Preview” button and “Generate”. Go to the URL http://localhost:8080/index.php?r=my-user, you will see the pst of all users.

Cpck 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