Running custom console actions via Controller

I have some custom yiic commands inside protected/commands/myCommands.php

I can run these fine by running


$> php yiic myCommand action

. But I need to create an admin panel and I want to run these commands via a controller. I looked at this tutorial (Run Yiic directly from your app without a shell ) but when I would do this my custom commands wouldn’t show up and I couldn’t run them. Yiic just showed message, migrate, shell and webapp. But not my custom commands.

Just looking for guidance on this and some examples.

Part 2 of this question is should I create a component or extension that plays a middle man between the controller and command class?

Replace the sample in there with your own console command and action




// Triggers actionBar() inside your FooCommand.php file

$args = array('yiic', 'foo', 'bar');



I think the problem with this is you won’t have any feedback while your console command is running. You would end up with your browser loading until the command finishes

That’s what I ended up doing but it rendered no response. The list of available commands does not list my custom actions in my command file. Any idea how to check ensure my command file is loaded in?




$commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';

$runner = new CConsoleCommandRunner();

$runner->addCommands($commandPath);



$commandPath should contain the correct path to your commands folder and inspecting $runner->commands after you have added your commands should return an array with all command files found inside that command folder.

Do you know what would cause it to not have any commands in it?

This is what $runner dumps out:




object(CConsoleCommandRunner)#86 (5) {

  ["commands"]=>

  array(0) {

  }

  ["_scriptName":"CConsoleCommandRunner":private]=>

  NULL

  ["_command":"CConsoleCommandRunner":private]=>

  NULL

  ["_e":"CComponent":private]=>

  NULL

  ["_m":"CComponent":private]=>

  NULL

}



I have my command file called ApiData.php in the commands directory (Screenshot)

This is from the yii docs about console commands (http://www.yiiframework.com/doc/guide/1.1/en/topics.console)

Naming convention might be your problem

Egg on my face. The one paragraph I did not read. Thanks for the help!