Gii Model Generator generates a CDbException - php

I am trying to create a simple web application using yii. I have install WAMP 2.5 and yii 1.1.x. I have also created a skeleton application called yiitest. I have also created a database with mysql called yiitest which has a table called persons and has the following columns: pid, fname, lname, dob, zip. I am trying to build the basic functionality of the web app using gii. I can log into gii and navigate to Controller Generator Form Generator and Module Generator, but when I try to click on Crud Generator or Model Generator I get a CDbException error.
Here is my code:
protected/config/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',
);
protected/config/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',
),
);
Any help on getting gii's Model Generator and Crud Generator working would be very helpful!
****Edit****
Here is a picture of the error I receive:

Could be you don'have a valid db connection
check in you dirname(__FILE__).'/database.php' if you have valid parameter
somethings like this
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=my_dbname',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'my_pwd',
'charset' => 'utf8',
),

Related

auditTrail yii extension

I am a newbie to yii and I am installing extension auditTrail.
I have made all the required changes to my main.php config file but everytime it is showing the same error
'Alias "auditTrail.AuditTrailModule" is invalid. Make sure it points
to an existing PHP file and the file is readable.'
Please help me out. thankyou in advance.. my editted file is here:
// 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.*',
'application.modules.auditTrail.models.AuditTrail',
),
'modules'=>array(
'auditTrail'=>array(),
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>false,
// 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>',
),
),
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=assetdb',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'Preksha#12',
'charset' => 'utf8',
),
'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',
),
);
here is the error ::
CException
Alias "auditTrail.AuditTrailModule" is invalid. Make sure it points to an existing PHP file and the file is readable.

Not able to make a model in gii model genrater

I am not able to create a model in yii model genrator.(Xamp on windows)
I am following the steps from http://www.yiiframework.com/forum/index.php/topic/32415-create-login-form/
I made change(s) in config/main.php file... paste the db name there "as test".
I created a user table in my database "test".
while using gii ..it is not creating model and showing me error
Error
Table 'user' does not exist.
I do not know what i am missing .
here is my config/main.php file view
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'gii',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
),
/*
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/test.db',
),*/
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=test',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),

Yii Bootstrap not working, the grid is huge, the dropdowns don't drop, toggles fail to do so

The page has bootstrap skin but I'm not sure why some actions like showing the list on dropdown navbar, the loading option on button doesn't work either, the grid is huge, etc.
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'name project',
// preloading 'log' component
'theme'=>'bootstrap',
'preload'=>array('log', 'bootstrap'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'ext.bootstrap-theme.widgets.*',
'ext.bootstrap-theme.helpers.*',
'ext.bootstrap-theme.behaviors.*',
),
'language'=>'es',
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'swjskowk',
'ipFilters'=>array('127.0.0.1','::1'),
'generatorPaths'=>array(
'ext.bootstrap-theme.gii',
'bootstrap.gii',
),
),
),
// application components
'components'=>array(
'bootstrap'=>array(
'class'=>'ext.bootstrap.components.Bootstrap',
),
'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>',
'gii'=>'gii',
'gii/<controller:\w+>'=>'gii/<controller>',
'gii/<controller:\w+>/<action:\w+>'=>'gii/<controller>/<action>',
),
),?>
I have a folder names bootstrap on themes, a bootstrap on extensions and bootstrap-theme on extensions again
Fix components section
'bootstrap'=>array(
'class'=>'ext.bootstrap.components.Bootstrap',
),
I think it should be
bootstrap'=>array(
'class'=>'bootstrap.components.Bootstrap',
),
Could be that you are not loading the javascript that needs the boostrap in order to be able to show the dropdown list in the nav bar and so on.

Yii Framework not returning proper WebUser class with Yii-user extension

I have Yii-User installed inside of Yii webapp. However, if I print out the User object using this: Yii::app()->user I get CWebUser class instead of the Yii-user extended class WebUser.
My main.php config is setup as below:
...
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
'loginUrl' => '/user/login',
'class' => 'WebUser',
),
),
...
I believe you have correctly configured configured the rest of the module:
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.user.models.*',
'application.modules.user.components.*',
),
...
'modules'=>array(
#...
'user' => array ( ... )
),
If so, and it still doesn't work, try configuring the user component like this:
...
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
'loginUrl' => '/user/login',
'class' => 'application.modules.user.components.WebUser',
),
),
...

Login Error in YII Framework

I am new to the beautiful Yii Framework. So I am just going through the tutorials and documentation. So I am doing the blog tutorial from starting. So for blog application I made export the database from the blog folder which comes with Yii to MySQL. Again I decided to use Yii User module and for that I made export the user module database to MySQL. Now my problem is that when I am using login in the application it is showing some error like this
Trying to get property of non-object
I both tried index.php?r=site/login and also index.php?r=user/login both failed. So can some one tell me how to solve this. FYI in my database there are two fields like 'ia_user' which is imported from the blog folder and 'ia_users' which is imported from the Yii User module folder. So is there any thing wrong. Below I am pasting the configuration of main.php file.
<?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 Blog Application',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
/*user module starts here*/
'application.modules.user.models.*',
'application.modules.user.components.*',
/*user module ends here*/
),
'modules'=>array(
// uncomment the following to enable the Gii tool
/*
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'Enter Your Password Here',
// 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,
/*user module starts here*/
'loginUrl' => array('/user/login'),
/*user module ends here*/
),
// 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>',
),
),
*/
//'db'=>array(
// 'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
//),
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=tbl_blog',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'tablePrefix'=> 'tbl_',
),
'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',
),
);
Please help me out.Any help and suggestions will be highly appreciable.I asked help from Yii forum but not got any reply So I am asking for help here .
I had to add user in array of modules just like this
'user'=>array(
'user'
// enable cookie-based authentication
'allowAutoLogin'=>true,
/*user module starts here*/
'loginUrl' => array('/user/login'),
/*user module ends here*/
),

Categories