Configuring Yii with additional modules

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

);

 

 



If you found this article useful » please +1 me on Google.