在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 Generator界面,填写表格。

步骤2-然后,单击“预览”按钮,然后单击“生成”。转到URL http:// localhost:8080 / index.php?r = my-user,您将看到所有用户的列表。

步骤3-打开URL http:// localhost:8080 / index.php?r = my-user / create。您应该看到用户创建表单。

作者:terry,如若转载,请注明出处:https://www.web176.com/yii/337.html
支付宝
微信