CConsoleCommandRunner calls init() right before it calls run() on the instantiated CConsoleCommand. I can’t imagine a reason why this shouldn’t work. Can you post an example of the code that’s not working?
I see. You’re referring to the case of executing your command from within the yiic shell? I must admit, that I didn’t use that shell for quite some time… You’re aware of the fact that you don’t need to use that shell?
For example, my commands are stored under protected/commands (default for CConsoleApplication::commandPath) and I use them this way:
Yii command runner (based on Yii v1.1.7)
Usage: D:\wamp\www\yiiSignalsDemo\trunk\protected\yiic.php <command-name> [parameters...]
The following commands are available:
- signal <-- custom one
To see individual command help, use the following:
D:\wamp\www\yiiSignalsDemo\trunk\protected\yiic.php help <command-name>
D:\wamp\www\yiiSignalsDemo\trunk>protected\yiic.bat help signal
Usage: D:\wamp\www\yiiSignalsDemo\trunk\protected\yiic.php signal <action>
connect --signalId=value --cmd=value
D:\wamp\www\yiiSignalsDemo\trunk>protected\yiic.bat signal list
No need to enter the yiic shell first. Maybe this can help.
For the invocation of commands through yiic shell, I can confirm, that CustomCommand::init() won’t be called.
I’ve moved into that use now, leaving the shell. I was overriding teh constructor without calling the ancestor constructor with the args, and I was overriding CConsoleCommand::run($args) as described in the agile yii book. I had no good reason to do that in my bootstrapdb method. As soon as I removed my override the init() was called by the console runner