Hello,
I have a little problem with method forward Dispatcher between two Controllers (so I have more controllers but the problem is with LlamadaSv Controller when I use forward method from other Controller).
First I must say which I'm using routes annotations, I displayed my routes.php:
//Use the annotations router
$router = new \Phalcon\Mvc\Router\Annotations(false);
$router->removeExtraSlashes(true);
$router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
// Contrato - Controller 1
$router->addResource('Contrato', '/contrato');
// LlamadaSv - Controller 2
$router->addResource('LlamadaSv', '/llamada_servidores');
// ... Other routes
$router->notFound([
"controller" => "error",
"action" => "show404Action"
]);
return $router;
In my services file:
// Dispatcher
$di->set('dispatcher',function() use ($di)
{
$evManager = $di->getShared('eventsManager');
$evManager->attach
(
"dispatch:beforeException",
function($event, $dispatcher, $exception)
{
switch ($exception->getCode())
{
case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(
array(
'controller' => 'Error',
'action' => 'show404',
)
);
return false;
}
}
);
$dispatcher = new PhDispatcher();
$dispatcher->setEventsManager($evManager);
return $dispatcher;
},
true
);
/**
* Loading routes from the routes.php file - Routing Anottations
*/
$di->set('router', function () {
return include __DIR__ . '/routes.php';
}, true);
So my controllers:
class ControllerBase extends Controller
{
protected function initialize()
{
$this->tag->prependTitle('SIPV | '); // Title Page
}
}
use Phalcon\Mvc\Model\Criteria;
use Phalcon\Paginator\Adapter\Model as Paginator;
/**
* @RoutePrefix("/llamada_servidores")
*/
class LlamadaSvController extends ControllerBase
{
public function initialize(){
$this->tag->setTitle('Llamada');
parent::initialize();
$this->view->setTemplateAfter("sipv");
}
/**
* @Route("/inicio")
*/
public function inicioAction(){
// foo code
}
/**
* @Route("/validar")
*/
public function validarAction(){
//This Action is a test, work well
$this->dispatcher->forward(array(
'controller' => 'LlamadaSv',
'action' => 'inicio'
));
}
// ... others acctions
}
/**
* @RoutePrefix("/contrato")
*/
class ContratoController extends ControllerBase
{
public function initialize(){
$this->tag->setTitle('Contrato');
parent::initialize();
$this->view->setTemplateAfter("sipv");
}
/**
* @Route("/prueba")
*/
public function pruebaAction(){
// Don't work
$this->dispatcher->forward(array(
'controller' => 'LlamadaSv',
'action' => 'inicio'
));
}
// ... others acctions
}
On the other hand, inside LlamadaSv Controller the forward method to same Controller work fine (Action Validar). But when I use forward method to LlamadaSv Controller from a diferent Controller, It display the exception 404 not found.
I hope anybody can help me, thanks!