Copyright © 2022-2025 aizws.net · 网站版本: v1.2.6·内部版本: v1.25.2·
页面加载耗时 0.00 毫秒·物理内存 153.5MB ·虚拟内存 1438.1MB
欢迎来到 AI 中文社区(简称 AI 中文社),这里是学习交流 AI 人工智能技术的中文社区。 为了更好的体验,本站推荐使用 Chrome 浏览器。
在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',
];
}
}
?>
让我们为MyUser模型生成CRUD。
第1步 - 打开CRUD生成器界面,填写表格。

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

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

让我们看看如何生成一个控制器。步骤1 - 要生成具有多个动作的控制器,请打开控制器生成器界面填写表单。第2步 - 然后,点击“预览”按钮和“生成”。 包含index,hel ...