Gii Model Generator生成CDbException

时间:2015-11-16 00:04:34

标签: php yii gii

我正在尝试使用yii创建一个简单的Web应用程序。我已经安装了WAMP 2.5和yii 1.1.x.我还创建了一个名为yiitest的骨架应用程序。我还创建了一个名为yiitest的mysql数据库,它有一个名为persons的表,并包含以下列:pid,fname,lname,dob,zip。我正在尝试使用gii构建Web应用程序的基本功能。我可以登录到gii并导航到Controller Generator表单生成器和模块生成器,但是当我尝试单击Crud Generator或Model Generator时,我收到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'=>'webmaster@example.com',
        ),
);

任何有关使gii的模型生成器和Crud Generator工作的帮助都会非常有用!

**** ****编辑 这是我收到的错误的图片:

CDbException Error

1 个答案:

答案 0 :(得分:0)

你可能没有有效的数据库连接

如果您有有效的参数

,请检查dirname(__FILE__).'/database.php' 像这样的事情

    'db'=>array(
        'connectionString' => 'mysql:host=localhost;dbname=my_dbname',
        'emulatePrepare' => true,
        'username' => 'root',
        'password' => 'my_pwd',
        'charset' => 'utf8',
    ),
相关问题