By default the console config doesn’t inherit settings from the main.php config file. to get a component enabled, you have to specify it in the console config explicitly, this goes for the user component which is the error you have found.
config/base.php: contains configuration shared by web app and console app (maybe like your DB connection?)
config/console.php: contains configuration which is specific to the console app (maye the name?)
config/main.php: contains configuration which is specific to the web app (like default controller - console apps don’t have such a property)
Then, you write config/base.php as you’re used to write it, simply return the array:
// This is the application's base configuration. Any writable
// CWApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Signals Demo',
// preloading 'log' component
'preload' => array( 'log' ),
[...]
};
For the main config and the console config, you merge the base config with the stuff that need to be specialized:
I’ve added the user component, which point to WebUser (which extends CWebUser). This is calling the init function of WebUser.
public function init()
{
parent::init();
Yii::app()->getSession()->open();
if($this->getIsGuest() && $this->allowAutoLogin)
$this->restoreFromCookie();
else if($this->autoRenewCookie && $this->allowAutoLogin)
$this->renewCookie();
if($this->autoUpdateFlash)
$this->updateFlash();
$this->updateAuthStatus();
}
Now, I’m getting error “CConsoleApplication doesn’t have a method named ‘getSession’.”
If I comment out the the body of the method, all’s good. Is the CConsoleApp supposed to load the WebUser component or am I supposed to use a Console specific component?
How can I use actions in which I use userGroups in Commands application?
Here the error if I simply try to use them in my app:
exception 'CException' with message 'CConsoleApplication and its behaviors do not have a method or closure named "getSession".' in /var/www/mandolini/www/yii/framework/base/CComponent.php:269
How can I log in as administrator in console mode?