We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

All the requests touted to index controller.

I am beginner to Phalcon and trying simple user module. It works fine with apache on my local machine and i am using nginx on server. Config looks fine and i do get proper URI params, but it always goes to index controller. url : 39.59.26.52/users/register



8.7k

When I was starting out, my prob was usually not picking the correct view. Try something like this

$this->view->pick("users/register");

Where register.volt is in your views/users directory

Please post your public function registerAction() { ... } from UsersController.php for further help.

@Ty Kroll : thanks for the reply.

I am not facing problem with the view, my all requests goes to indexController. check this Url :139.59.26.52/users/register 139.59.26.52/foo/bar This loads my indexAction from indexControllers and in index action I dumped URI and its giving proper URI whihc i am requesting. 139.59.26.52/nocontrollerinthisname/noaction



8.7k

Make sure you register your controller directory in your Phalcon\Loader and have the proper filename for your controller file with a matching class declaration.

Follow this: https://github.com/phalcon/mvc/blob/master/simple/public/index.php

Hi, be sure your paths looks like this

views/index/index.phtml

views/other_controller/index.phtml

I remeber in the past that all my requests were going to index.phtml because I had this path:

views/index.phtml

Here's the documentation:

hierarchical-rendering

Nginx config

server {

listen   80;

index index.php index.html index.htm;
set $root_path /var/www/html/store/public;
root $root_path;
server_name 139.59.26.52;
location / {
    try_files $uri $uri/ /index.php;
}

location ~ \.php$ {
    try_files     $uri =404;

    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;

    include fastcgi_params;
    fastcgi_split_path_info       ^((?U).+\.php)(.*)$;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
    #fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}

location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}

}

Loader (app/config/loader.php) <?php

$loader = new \Phalcon\Loader();

$loader->registerDirs( [ $config->application->controllersDir, $config->application->modelsDir ] )->register();

IndexController.php

<?php

class IndexController extends ControllerBase {

public function indexAction()
{
   $this->view->disable();
    echo ($_SERVER['REQUEST_URI']);
}

}

TestController.php

<?php

class TestController extends ControllerBase {

public function indexAction()
{
    $this->view->disable();
    echo 'Test';
}

}

139.59.26.52/index/index

then it should display

/index/index

139.59.26.52/test/index

then it should display

Test

but i get /test/index

Show please whole file structure of your app

i created app through phalcon command and added testcontroller

It's hard to help you if you don't resposne for my asks ;-)



77.7k
Accepted
answer
edited Jan '17

My first guess is that you have an url source mismatch

Phalcon can have two sources for URI: get parameter ($_GET['_url']) OR request uri ($_SERVER['REQUEST_URI']) In your nginx config, you haven't provided the get parameter which is used by default.

If you want to use request uri (i prefer this one, so no extra get parameter is injected to each request):

// somewhere in your php bootstrap, preferably where you init the router component
$router->setUriSource(Router::URI_SOURCE_SERVER_REQUEST_URI);

https://docs.phalcon.io/en/latest/reference/routing.html#uri-sources

If you want the query approach:

# nginx vhost file
    location / {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }

https://docs.phalcon.io/en/3.0.0/reference/nginx.html

My second guesss is that your router rules are messed up

If you register a generic router pattern like /:controller/:action/:params as the LAST rule, it will forward every request to index

nginx vhost file

location / {
    try_files $uri $uri/ /index.php?_url=$uri&$args;
}

I dunno how I missed this :P.

Thanks a lot @Lajos @PolDeveloper :)