我想用yii创建一个简单的web应用程序。我已经安装了WAMP 2.5和yii 1.1.x.我还创建了一个名为yiitest的框架应用程序。我还创建了一个名为yiitest的mysql数据库,其中有一个名为persons的表,并具有以下列:pid,fname,lname,dob,zip。我正在尝试使用gii构建Web应用程序的基本功能。我可以登录到gii并导航到控制器生成器表单生成器和模块生成器,但是当我尝试点击Crud生成器或模型生成器时,我得到一个CDbException错误。Gii模型生成器生成一个CDbException
这里是我的代码:
保护/配置/ database.php中
<?php
// This is the database connection configuration.
return array(
//'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
// uncomment the following lines to use a MySQL database
'connectionString' => 'mysql:host=localhost;dbname=yiitest',
'emulatePrepare' => true,
'username' => 'yiiUser',
'password' => 'p4ssw0rd',
'charset' => 'utf8',
);
保护/配置/ main.php
<?php
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Web Application',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'password',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
),
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// uncomment the following to enable URLs in path-format
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
// database settings are configured in database.php
'db'=>require(dirname(__FILE__).'/database.php'),
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
/*
array(
'class'=>'CWebLogRoute',
),
*/
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'[email protected]',
),
);
上获得GII的模型生成和界面污物任何帮助发电机的工作将是非常有益的!
**** ****编辑 以下是错误的图片我收到:
什么是您的CdbException错误的详细资料? – Joey
CDbException下的grat文本区域中没有任何内容,但是对于行错误,这是突出显示的内容:C:\ wamp \ www \ yii \ framework \ gii \ generators \ model \ ModelCode.php(60)58 public function init () 60 if(Yii :: app() - > {$ this-> connectionId} === null) 61 throw new CHttpException(500,'运行此生成器需要有效的数据库连接。 ); 62 $ this-> tablePrefix = Yii :: app() - > {$ this-> connectionId} - > tablePrefix; parent :: init(); 64} – user908759
@ user908759尝试在'database.php'文件中使用'127.0.0.1'而不是'localhost'。 – Criesto