Hello! How to use tasks in namespace?
/path/to/myapp$ tree -L 2 ..
..
|-- models
| |-- Base.php
| |-- Users.php
|-- private
| `-- cli.php
|-- public
| `-- index.php
|-- tasks
| |-- MainTask.php
| `-- TestTask.php
..
/path/to/myapp/private$ cat cli.php
<?php
define('ROOT_PATH', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
// Load Phalcon
$loader = new \Phalcon\Loader();
$loader
->registerNamespaces([
'MyApp\Models' => ROOT_PATH . 'models/',
'MyApp\Controllers' => ROOT_PATH . 'controllers/',
'MyApp\Tasks' => ROOT_PATH . 'tasks/', // Does not working
])
->registerDirs([
ROOT_PATH . 'models/',
ROOT_PATH . 'controllers/',
ROOT_PATH . 'tasks/',
])
->register()
;
// Load Composer
require_once ROOT_PATH . 'vendor/autoload.php';
// App
$cli = new \Phalcon\CLI\Console();
$cli->setDI($di);
// Parse args
$args = [];
$params = [];
foreach ($argv as $k => $arg)
if ($k == 1)
$args['task'] = $arg;
elseif ($k == 2)
$args['action'] = $arg;
elseif ($k >= 3)
$params[] = $arg;
if (count($params) > 0)
$args['params'] = $params;
var_export($loader); // Registering is OK: \Phalcon\Loader::_registered == true
// Run app
$cli->handle($args);
If MainTask is not namespaced – works perfectly.
But if i just add namespace (MyApp\Tasks) to any task – i get an exception: "Phalcon\CLI\Dispatcher\Exception: MainTask handler class cannot be loaded".
How to solve this? Extending framework? I don't know C/C++ and can't see sources ):
Thanks!