Ok where to start...
I want a structure like this:
/public
/app
/app/cache
/app/config
/src
/src/Vendor
/src/Vendor/Module
So I want my modules in /src and I want the annotation router to parse all my controllers in that module (and add those to the global routing table) I do NOT want to add every controller manually when I create a new controller file.
So far my bootstrap looks like this:
<?php
use Phalcon\Mvc\Router,
Phalcon\Mvc\Application,
Phalcon\DI\FactoryDefault,
Phalcon\Exception;
$di = new FactoryDefault();
$di->set('router', function()
{
$router = new \Phalcon\Mvc\Router\Annotations(false);
$router->setDefaultModule('ServerManager');
$router->setDefaultNamespace('Dalu\ServerManager');
$router->addModuleResource('ServerManager','Dalu\ServerManager\Index');
//var_dump($router);
return $router;
});
try
{
//Create an application
$application = new Application();
$application->setDI($di);
$application->registerModules(
array(
'ServerManager' => array(
'className' => 'Dalu\ServerManager\Module',
'path' => dirname(__DIR__) . '/src/Dalu/ServerManager/Module.php'
)
)
);
//Handle the request
echo $application->handle()->getContent();
}
catch(Exception $e)
{
echo $e->getMessage();
}
Module.php
<?php
namespace Dalu\ServerManager;
use Phalcon\Loader,
Phalcon\Mvc\Dispatcher,
Phalcon\Mvc\View,
Phalcon\Mvc\ModuleDefinitionInterface;
class Module implements ModuleDefinitionInterface
{
/**
* Register a specific autoloader for the module
*/
public function registerAutoloaders()
{
echo "RegisterAutoloaders:" . __DIR__ . "\n";
$loader = new Loader();
$loader->registerNamespaces(
array(
'Dalu\ServerManager\Controller' => __DIR__ . 'Controller/',
'Dalu\ServerManager\Model' => __DIR__ . 'Model/',
)
);
$loader->register();
}
/**
* Register specific services for the module
*/
public function registerServices($di)
{
//Registering a dispatcher
$di->set('dispatcher', function()
{
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Dalu\ServerManager\Controller');
return $dispatcher;
});
//Registering the view component
$di->set('view', function()
{
$view = new View();
$view->setViewsDir('Views/');
return $view;
});
}
}
Error:
Fatal error: Uncaught exception 'ReflectionException' with message 'Class Dalu\ServerManager\IndexController does not exist' in /home/darko/NetBeansProjects/phal/app/bootstrap.php:51
Stack trace:
#0 [internal function]: ReflectionClass->__construct('Dalu\ServerMana...')
#1 [internal function]: Phalcon\Annotations\Reader->parse('Dalu\ServerMana...')
#2 [internal function]: Phalcon\Annotations\Adapter->get('Dalu\ServerMana...')
#3 [internal function]: Phalcon\Mvc\Router\Annotations->handle(NULL)
#4 /home/darko/NetBeansProjects/phal/app/bootstrap.php(51): Phalcon\Mvc\Application->handle()
#5 /home/darko/NetBeansProjects/phal/public/index.php(4): require('/home/darko/Net...')
#6 {main} thrown in /home/darko/NetBeansProjects/phal/app/bootstrap.php on line 51
line 51:
echo $application->handle()->getContent();
Can this be done and if so, how?