I've built a website with phalcon that has the following controller structure:
- controllers
-
- admin
-
-
- TicketsController.php
-
and the following views structure
- views
-
- admin
-
-
- tickets
-
-
-
-
- case.volt
-
-
-
-
-
- index.volt
-
-
This is my routes.php file. It routes the controllers within the Myapp\Controllers\Admin namespace to a url with /admin prefixed.
<?php
$router = new Phalcon\Mvc\Router();
$router->setDefaults([
"controller" => "index",
'namespace' => 'Myapp\\Controllers',
]);
$router->add('/:controller/:action/:params', [
'controller' => 1,
'action' => 2,
'params' => 3,
]);
$router->add('/:controller/:action', [
'controller' => 1,
'action' => 2,
]);
$router->add('/:controller', [
'controller' => 1,
]);
$router->add('/admin/:controller/:action/:params', [
'namespace' => 'Myapp\\Controllers\\Admin',
'controller' => 1,
'action' => 2,
'params' => 3,
]);
$router->add('/admin/:controller/:action', [
'namespace' => 'Myapp\\Controllers\\Admin',
'controller' => 1,
'action' => 2,
]);
$router->add('/admin/:controller', [
'namespace' => 'Myapp\\Controllers\\Admin',
'controller' => 1,
]);
$router->add('/admin', [
'namespace' => 'Myapp\\Controllers\\Admin',
'controller' => 'admindashboard'
]);
$router->removeExtraSlashes(true);
return $router;
Every controller gets a manual change for ViewsDir:
public function initialize(){
$this->view->setViewsDir($this->view->getViewsDir() . "admin/" . $this->dispatcher->getControllerName() . "/");
}
Question:
I always get the index view when I go to any action within the Tickets controller. For example: /admin/tickets/case/ returns the index.volt instead of the case.volt.
How can this issue be solved?