yii框架之gii创建数据表对应的model类

一、首先是在数据库中建立工程需要的表;

二、然后,配置对应文件:

在工程目录下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类和其他模块了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值