Not able to make a model in gii model genrater - php

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',
),

Related

Yii2: Error 404 after using Gii for a new database schema

I used Gii code generator to create a model and its CRUD for a table located in the non public schema but then the URL is not working: Error 404 not found.
I have a PostgreSQL database called travels with two schemas: public and laboratory. Everything works perfect using the public schema.
Now I need to use the laboratory schema that I created recently. So I created the model (a minor problem: autocomplete doesn't work for laboratory schema but the model is created anyway):
Then I created the CRUD:
Then I try to see the results:
It's my common/config/main-local.php file:
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=localhost;dbname=travel',
'username' => 'aaaa',
'password' => 'bbbb',
'charset' => 'utf8',
],
],
];
The problem was that I modified this file before and something was not right:
/vendor/yiisoft/yii2-gii/generators/crud/default/views
The problem about model autocomplete is still there.
Copy the file gii.js from vendor/yiisoft/yii2-gii/assets to the directory where you throw the error for your case will vary.

Gii Model Generator generates a CDbException

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',
),

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.

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