一、首先是在数据库中建立工程需要的表;
二、然后,配置对应文件:
在工程目录下yiiProject\protected\config\main.php。在50行定义了db应用组件,下面后一段注释掉了的mysql的链接配置项,我们将未注释的db注释掉,然后打开mysql链接代码并填写相关信息即可完成mysql链接配置项。
即,把下面代码
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
// uncomment the following to use a MySQL database
/*
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=myemail',
'emulatePrepare' => true,
'username' => 'root',
'password' => '123',
'charset' => 'utf8',
),
*/
改为:
/* 'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
*/
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=myemail',
'emulatePrepare' => true,
'username' => 'root',
'password' => '123',
'charset' => 'utf8',
),
三、在工程目录下yiiblog\protected\config\main.php,在配置文件的21行,将模块配置里的gii部分去掉注释即可。在红色框里填写一个密码,使用gii的密码。
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'123',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
),
四、接下来在
浏览器中访问gii模块即可,访问路径:http://localhost/
yiiProject/index.php?r=gii,输入红色框中定义的密码即可进入gii模块。脚手架页面的首页显示脚手架提供如下功能:
下面就可以生成对应数据库表的model类和其他模块了。