Hi,
lets say I have an application using the annotations router and I want to generate links using Phalcon\Mvc\Url.
Setup is:
<?php
try {
//Register an autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
'../app/controllers/',
))->register();
//Create a DI
$di = new Phalcon\DI\FactoryDefault();
//Setting up the view component
$di->set('view', function () {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../app/views/');
return $view;
});
$di->set('router', function () {
$router = new \Phalcon\Mvc\Router\Annotations(false);
$router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
$router->removeExtraSlashes(true);
$router->add("/", array('controller' => 'index','action' => 'index'));
$router->notFound(array("controller" => "error", "action" => "notFound"));
$router->addResource('Index', '/');
$router->addResource('Authentication', '/auth');
return $router;
});
$di->set('url', function() {
$url = new \Phalcon\Mvc\Url();
return $url;
});
//Handle the request
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle()->getContent();
} catch (\Phalcon\Exception $e) {
echo "PhalconException: ", $e->getMessage();
}
My IndexController has an action like:
<?php
/**
* @RoutePrefix("")
*/
class IndexController extends \Phalcon\Mvc\Controller
{
/**
* @Get("/")
*/
public function indexAction()
{
echo $this->url->get(array('for'=>'indexTestRoute','testParam'=>'routingTest','testId'=>12)); // This one works
echo $this->url->get(array('for'=>'loginRoute')); // This one throws: PhalconException: Cannot obtain a route using the name "loginRoute"
}
/**
* @Get("/test/{testParam:[a-zA-Z]+}/{testId:[0-9]+}", name="indexTestRoute")
*/
public function testAction($testParam, $testId) {
}
}
And my AuthenticationController:
<?php
/**
* @RoutePrefix("/auth")
*/
class AuthenticationController extends \Phalcon\Mvc\Controller
{
/**
* @Get("/login", name="loginRoute")
*/
public function loginAction() {
}
}
So how can I tell Phalcon\Mvc\Url that the route "loginRoute" can be found in the AuthenticationController? Or is this what I'm doing super bad regarding the overall performance?
(The routes /auth/login and /test/routingTest/12 do work btw.)
Thank you, Toby