Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Routes - Need a Pointer on Public/subdir

First of all, let me note that I am reading the routing docs...but not 100% certain what I am loking for. So, I think this will amount to something easy and I need a pointer in the correct direction.

I am writing a multi module site (backend and frontend). Started with the great example at: https://github.com/phalcon/mvc/tree/master/multiple-shared-layouts

I am trying to route the following url: /localhost/test to a layout in /apps/backend/layouts/test.phtml as such:

$router->add('/test', array( 'module' => 'backend', 'controller' => 'index', 'action' => 'index' ));

What I get is a printout of the file contents of the /test directory (Which contains all the supporting media files...so I see an images directory, a css directory, etc...) This is presented instead of the layout defined in /apps/backend/layouts/test.phtml which should reference said support files.

Any pointers would be greatly appreciated!!



11.1k

you have actual /test folder in the public directory? if so you need either to add a .htaccess to it or rename the folder. Phalcon .htaccess is going to route all calls from none existing directory



7.8k
Accepted
answer

here is my folder skeletopn

/myapp/app/controller/admin

and this is my route code

/myapp/app/config/routes.php

$router = new Phalcon\Mvc\Router();
/**
 * Create Route Admin Backend
 **/
$routing = array(
    '/admin/dashboard' => array(
        'namespace' => 'app\controllers\admin',
        'controller' => 'dashboard',
        'action' => 'index'),
    '/admin/system' => array(
        'namespace' => 'app\controllers\admin',
        'controller' => 'system',
        'action' => 'index'),
);

foreach ($routing as $k => $v) {
    $router->add($k, $v);
}

return $router;

it's work for me