[trick] share config cross web & console app

lately it took me a while to figure out why migration does not work till i open the default sqlite db;

i changed db in config/main.php while not at the same time in console.php, here is what i come up with small trick:

in config/console.php


<?php

//load main config

$_main = include_once( 'main.php' );


// This is the configuration for yiic console application.

// Any writable CConsoleApplication properties can be configured here.

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'My Console Application',

	// application components

	'components'=>array(


        //share db connection with webapp

        'db'=>$_main['components']['db'],	   

	//'db'=>array(

	//	'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

	//),

	// uncomment the following to use a MySQL database

	/*

	'db'=>array(

		'connectionString' => 'mysql:host=localhost;dbname=testdrive',

		'emulatePrepare' => true,

		'username' => 'root',

		'password' => '',

		'charset' => 'utf8',

	),

	*/

        ),

);

[color="#008000"]NOTE: moved to proper section (Tips, Snippets and Tutorials instead of General Discussion for Yii 1.1.x)[/color]