Phalcon\Cli Apps with namespaces in Phalcon\Loader


currently we are building up a CLI app. I prepared a standard bootstrap file and there everything which is need gets loaded.

In this file is a function:

     * Initializes the loader
    private function _initLoader(){
        if(count($this->_namespaces) > 0){
            $loader = new Phalcon\Loader();

The content of the $this->_namespaces looks like:

    'Path/To/Ns' => 'Path\To\Ns'

The task itself looks like:

namespace Path\To\Ns;

class AnyTask extends Phalcon\CLI\Task{

    public function mainAction(){
        echo "Main action ...";

    public function createAction(){
        echo "Create action ...";


I receive all the time the following message when I run my app:

php -f path/to/bootstrap.php any
# Output: AnyTask handler class cannot be loaded

Any ideas?

I'm not sure, but maybe the problem is in slashes. Namespace slashes is backslash() and path slashes is usual slash(/) Shouldn't is be like this?

    'Path\To\Ns' => 'Path/To/Ns'

Maybe it'll help, if not unfortunately I haven't any idea.


I also think the problem is the wrong namespace separator in the loader

Sorry, my mistake here. It should be for sure:

'Path\To\Ns' => 'Full/Path/To/Ns'

But anyway, it does not work for me.

Here is the real one to make it more clear :)

array(1) {
  string(94) "/var/deploy/local/"

Maybe now any ideas?


Check this example:



use Phalcon\Loader,
    Phalcon\DI\FactoryDefault\CLI as CliDI;

$loader = new Loader();

    'Db\Migration\CLI\Task' => __DIR__ . '/tasks/'

$di = new CliDI();

$app = new Console();


$app->handle(array('task' => 'Db\Migration\CLI\Task\Any'));



namespace Db\Migration\CLI\Task;

class AnyTask extends \Phalcon\CLI\Task

    public function mainAction()
        echo "Main action ...";

    public function createAction()
        echo "Create action ...";



Hi I'm having the same kind of problem but with my models :

$loader = new \Phalcon\Loader();


    'Tuango\CLI\Task' => APPLICATION_PATH . '/tasks',
    'Tuango\CLI\Security' => APPLICATION_PATH . '/lib/Tuango/CLI/Security/',
    'Tuango\Models' => APPLICATION_PATH . '/models/Tuango/Models/'



        //APPLICATION_PATH . '/tasks',
        //APPLICATION_PATH . '/models'


Parent class :

namespace Tuango\CLI\Security;

abstract class FraudĀ  {
    //Abstract stuff here

Child class :

namespace Tuango\CLI\Security;

use Tuango\CLI\Security\Fraud;

class LiveFraud extends Fraud {
    //Class stuff and abstract method inherited

Task :

namespace Tuango\CLI\Task;

use Tuango\CLI\Security\LiveFraud;

class FraudTask extends \Phalcon\CLI\Task {

    public function mainAction() {

        $liveFraud = new LiveFraud();

Fatal error: Class 'Tuango\CLI\Security\Fraud' not found in /Library/WebServer/Documents/tuangocli/app/lib/Tuango/CLI/Security/LiveFraud.php on line 30

I can't figurate out what's the problem here.

Any help would be appreciated :)

Thank you.


here is my idear

$di->setShared('dispatcher', function () {
    $dispatcher = new Phalcon\CLI\Dispatcher();
    return $dispatcher;