Hmm, I never try without namespaces because this is a good practice.
There are a few things which you must do it to subcontrollers works.
Erorrs * handler class cannot be loaded
means that you don't tell phalcon where can find your class.
You must register namespace in \Phalcon\Loader(). If you using one of default project architecture the loader should be in app/config/loader.php
.
Open this file and fill like this:
$loader = new Phalcon\Loader();
//Register some namespaces
$loader->registerNamespaces(array(
'MyApp\Controllers\Admin\' => __DIR__ . '/../controllers/admin/', // this should be a path do your subcontroller dir
));
//register autoloader
$loader->register();
You should create also a custom router. Create a file router.php in app/config/router.php
with content like this:
$router = new \Phalcon\Mvc\Router(true);
// Route for dashboard/homepage
$router->add("/[/]?", array(
'namespace' => 'MyApp\Controllers\\',
'controller' => 'index',
'action' => 'index',
));
// Route for default controller action
$router->add("/:controller[/]?", array(
'namespace' => 'MyApp\Controllers\\',
'controller' => 1,
'action' => 'index',
));
// Route for controller action
$router->add("/:controller/:action[/]?", array(
'namespace' => 'MyApp\Controllers\\',
'controller' => 1,
'action' => 2,
));
// Route for controller action params
$router->add("/:controller/:action/:params[/]?", array(
'namespace' => 'MyApp\Controllers\\',
'controller' => 1,
'action' => 2,
'params' => 3,
));
$router->add("/admin[/]?", array(
'namespace' => 'MyApp\Controllers\Admin\\',
'controller' => 'index',
'action' => 'index',
));
// Route for default controller action
$router->add("/:controller[/]?", array(
'namespace' => 'MyApp\Controllers\Admin\\',
'controller' => 1,
'action' => 'index',
));
// Route for controller action
$router->add("/:controller/:action[/]?", array(
'namespace' => 'MyApp\Controllers\Admin\\',
'controller' => 1,
'action' => 2,
));
// Route for controller action params
$router->add("/:controller/:action/:params[/]?", array(
'namespace' => 'MyApp\Controllers\Admin\\',
'controller' => 1,
'action' => 2,
'params' => 3,
));
Next open your app/config/services.php
and add:
//Registering a router
$di->set('router', function() {
if (!file_exists(__DIR__ . '/router.php')) {
throw new \Exception('Router file does not exists!');
}
require_once __DIR__ . '/router.php';
return $router;
});
Now should be works