I got a bit confused initially when I tried to add the excellent User module into my first webapp. It all came down to the config/main.php and adding the extra parameters into the right place.
So for all you other noobs out there, here is my final config file:
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Application Name',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.user.models.*',
'application.modules.user.components.*',
),
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'Enter Your Password Here',
),
// This is where you add the Additional Parameters
// for the USER MODULE
'user'=>array(
'hash' => 'md5', # encrypting method (php hash function)
'sendActivationMail' => true, # send activation email
'loginNotActiv' => false, # allow access for non-activated users
'autoLogin' => true, # automatically login from registration
'registrationUrl' => array('/user/registration'), # registration path
'recoveryUrl' => array('/user/recovery'), # recovery password path
'loginUrl' => array('/user/login'), # login form path
'returnUrl' => array('/user/profile'), # page after login
'returnLogoutUrl' => array('/user/login'), # page after logout
'tableUsers' => 'tbl_users',
'tableProfiles' => 'tbl_profiles',
'tableProfileFields' => 'tbl_profiles_fields', ),
),
),
// application components
'components'=>array(
//These parameters are for the base Yii User component
// and should not get confused with the module parameters above
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
'loginUrl' => array('/user/login'),
),
'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=database',
'emulatePrepare' => true,
'username' => 'user',
'password' => 'password',
'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',
),
array(
'class'=>'CWebLogRoute',
),
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'me@me.com',
'defaultController' => 'user',
),
);
Blog
Photography
Portfolio
Yii Part 1
Great – Thank you for your help.
Just a small correction: under components you initialize ‘user’ two times. The second init is sufficient
Again, thanks that your post did save my time and accelerated learning all the many setting options.
Hi Dirk
Thanks for your feedback and pointing that out. I should have explained in my post; the first definition of 'user' is under modules and is there because I am using the user login extension module which you will find on the Yii extensions site here http://www.yiiframework.com/extension/yii-user/ I will add a comment to the example config.
The second definition is under components and defines the parameters for the standard User component under Yii.
Thanks,
Chris
Hi Dirk
I finally bumped into the error you noted above and fixed it – thanks!
Chris