Using the configuration file, explain what can be configured.

You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#2) »

The configuration 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(
		
		// the base path to the protected folder
		// access it using Yii::app()->basePath
		'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
		
		// name of application
		// access it using Yii::app()->name
		'name'=>'My website',
		
		// default controller that will be executed when running the application
		'defaultController'=>'site', 
		
		// source language of the application
		'language'=>'es',
		
		// charset to use
		'charset'=>'utf-8',

		// preloading application components
		'preload'=>array('log'),

		// autoloading classes
		'import'=>array(
			'application.models.*',
			'application.components.*',
		),

		// application-level parameters that can be accessed
		// using Yii::app()->params['paramName']
		'params'=>array(
			'adminEmail'=>'info@example.com',
		),
		
		// Note: you can also separate your configuration file into
		// more files, for example: db.php, params.php and so on.
		// You can do it like this example:
		// 'params'=>require(dirname(__FILE__).'/params.php'),
		// and inside the params.php you will return the array:
		// return array('adminEmail'=>'info@example.com');

		// configuration of application components
		'components'=>array(
		
			// assets, see http://www.yiiframework.com/doc/api/CAssetManager
			'assetManager'=>array(
				// change the path on disk
				'basePath'=>dirname(__FILE__).'/../../assets/',
				// change the url
				'baseUrl'=>'/web/assets/'
			),
			
			// logging
			'log'=>array(
				// class of logger
				'class'=>'CLogRouter', 
				// where to store logs?
				'routes'=>array( 
					array(
						// store on file, other options are available
						'class'=>'CFileLogRoute', 
						// what to store on file? error and warning, info and trace can be added here
						'levels'=>'error, warning', 
					),
				),
			),
			
			// user
			'user'=>array(
				// enable cookie-based authentication
				'allowAutoLogin'=>true,
				// set the url where user must be redirected if authentication needed
				// use null to force 403 HTTP error 
				'loginUrl'=>null,
				// set here the name of a class
				// that extends CWebUser and it is stored in
				// protected/components/<classname>
				// see: http://www.yiiframework.com/forum/index.php?/topic/5610-extend-cwebuser/
				'class' => 'WebUser',
			),
			
			// database
			'db'=>array(
				// using mysql
				'connectionString'=>'mysql:host=example.com;dbname=my_db',
				'username'=>'my_user',
				'password'=>'my_password',
				// set the charset of the connection
				'charset'=>'utf8',
				// using sqlite
				// 'connectionString'=>'sqlite:'.dirname(__FILE__).'/../data/blog.db',
			),
			
			// url 
			'urlManager'=>array(
				// the URL format. It must be either 'path' or 'get'.
				// path: index.php/controller/action/attribute/value
				// get: index.php?r=controller/action&attribute=value
				'urlFormat'=>'path',
				// show www.example.com/index.php/controller/action 
				// or just www.example.com/controller/action
				'showScriptName' => true,
				// rules to redirect a specific url to the controller you want
				// see: http://www.yiiframework.com/doc/guide/topics.url
				'rules'=>array(
					// www.example.com/home instead of www.example.com/site/index
					'home'=>'site/index',
					'post/<id:\d+>'=>'post/show',
				),
			),
		),
	);
	?>
17 0
14 followers
Viewed: 90 865 times
Version: Unknown (update)
Category: Tutorials
Tags:
Written by: atrandafir
Last updated by: Yang He
Created on: Jan 10, 2010
Last updated: 11 years ago
Update Article

Revisions

View all history