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.

Phalcon 2 nginx Router only index controller loaded

I started a new app using Phalcon 2, mostly by following the tutorial. I am using nginx set as here: https://phalcon-php-framework-documentation.readthedocs.org/en/latest/reference/nginx.html?highlight=nginx#nginx-installation-notes The router always loads the index controller and template.

$router = new Phalcon\Mvc\Router(false); $router->setUriSource(Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);

Also tested with the default $_GET['_url']

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

Added the same route different ways (only one active, two commented out), even tried with double slashes or without any.

$router->add("/signup", array( 'controller' => 'signup', 'action' => 'index' ));

$router->add("/signup", 'Signup::index'); $router->addGet("/signup", 'Signup::index');

The debugging here shows string(7) "/signup" so I don't think it's an nginx problem.

var_dump($router->getRewriteUri());

This one is null.

var_dump($router->getMatchedRoute());

This one returns an array with two Phalcon\Mvc\Router\Route objects.

var_dump($router->getRoutes());

This one is also null.

var_dump($router->getControllerName ());

I have the signup template and controller, but it's only loading the index one.



6.5k

I'm using phalcon 2 with nginx and it works fine. Post you nginx configuration for your website.

edited Dec '14

I don't think the problem is with nginx's config (the config is copy paste with root edited), because var_dump($router->getRewriteUri()); prints string(7) "/signup" I also used the config where I had the rewrite index.php?_url=/$1 and var_dump($router->getRewriteUri()); printed string(8) "//signup" I installed phalcon 2 last month, so I don't think I have the latest updates.



599
Accepted
answer

My bad, I had the index.phtml template directly in the views folder. not in views/index. The loaded controller was SignupController, but the template was index.phtml. I created the index folder, moved the file and it's ok now.