1:创建一个数据表,以下为示例可直接复制
CREATE TABLE `menus` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL COMMENT '菜单名称',
`status` int(11) DEFAULT '1' COMMENT '1使用2未使用',
`level` int(11) DEFAULT NULL COMMENT '级别',
`parentId` int(11) DEFAULT '0' COMMENT '父id',
`desc` varchar(255) DEFAULT NULL,
`sort` int(11) DEFAULT NULL,
`type` tinyint(4) DEFAULT '1' COMMENT '1前台2后台',
`creaTime` datetime DEFAULT NULL,
`updateTime` datetime DEFAULT NULL,
`creaId` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2:打开gii方式
---config/web.php中有以下代码,这里的gii下面的allowedIPs 可设置可不设置
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
'allowedIPs' => ['127.0.0.1'],
];
}
web/index.php中
defined('YII_ENV') or define('YII_ENV', 'dev');
3:访问地址,你的域名或者ip等+(加号忽略,我只是未了给大家展示清楚一点)index.php?r=gii,界面如下
4:刚刚创建了表 我们先生成model吧,点击Model Generator里的start,按图输入信息,点击preview
5:会给你看下你要生成的文件列表,如果没问题点击绿色的按钮,就生成了model,去文件夹中见图
6:创建控制器---Controller Generator,看图讲解
7:创建crud--CRUD Generator
8:好了,现在就可以看到效果了,咋们走起,访问下
你的域名或者ip+(加号忽略,我只是未了给大家展示清楚一点)/index.php?r=menus,
好了,最基础的增删改查有了,可以在根据自己的业务需求进行修改
完结