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 生成器界面,填写表单。
步骤 2 − 然后,点击"预览"按钮和"生成"。转到 URL http://localhost:8080/index.php?r=my-user,您将看到所有用户的列表。
步骤 3 −打开 URL http://localhost:8080/index.php?r=my-user/create。您应该会看到一个用户创建表单。