Revision #3 has been created by jacmoe on Aug 27, 2011, 2:34:56 AM with the memo:
Cleaned up code
« previous (#2)
Changes
Title
unchanged
Run Yiic directly from your app without a shell
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
yiic, console, cli, command, shell
Content
changed
[...]
### Run yiic migrate in an action
#### Code
```php
private function runMigrationTool() {
$commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
$runner = new CConsoleCommandRunner();
$runner->addCommands($commandPath);
$commandPath = Yii::getFrameworkPath() . DIRECTORY_SEPARATOR . 'cli' . DIRECTORY_SEPARATOR . 'commands';
$runner->addCommands($commandPath);
$args = array(
'command', 'yiic', 'migrate', '--interactive=0');
$command = $runner->createCommand($args[0]);
array_shift($args);
ob_start();
$runner->run($args);
echo htmlentities(ob_get_clean(), null, Yii::app()->charset);
}
```
#### How to use
You can call it from a controller action like this:
```php[...]