Can get controller & action name from $_SERVER['REQUEST_URI'] on phalcon v3.0.3

Hi all!

[My Question]

"Can get controller & action name from $SERVER['REQUESTURI'] on phalcon v3.0.3?"

nginx.conf(aws)


    location ~ \.php {
        fastcgi_pass php-fpm;
        try_files     $uri =404;
        fastcgi_index /index.php;
        include fastcgi_params;
        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
    }

When

ec2 ( Amazon Linux AMI ), Phalcon version:3.0.3, nginx/1.10.1, PHP 7.0.14 (fpm-fcgi) (built: Jan 18 2017 19:14:35)

invo/public/index.php


echo $application->handle(!empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null)->getContent();

This don't moved.

But, When

ec2 ( Amazon Linux AMI ), Phalcon 2.1.0r, nginx/1.10.1, PHP 7.0.14 (fpm-fcgi) (built: Jan 18 2017 19:14:35)

invo/public/index.php


echo $application->handle(!empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null)->getContent();

this is moved.

When

windows10 , XAMPP control Panel v3.2.2 , Apache 2.0 , PHP Version 7.0.13 , Phalcon 3.0.3

invo/public/index.php


echo $application->handle(!empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : null)->getContent();

this is moved.

The PHP source code is not the same on those servers. I'm sorry.

If there is the reason other than PHP source code, Please tell me the solution in that case.



3.0k
edited Apr '17

Perhaps I misunderstand your question, but there's 2 setups you can use on Phalcon on nginx: https://docs.phalconphp.com/en/3.0.0/reference/nginx.html

Using $_GET['_url'] as source of URIs

Using $_SERVER['REQUEST_URI'] as source of URIs:

It seems your location block for php is wrong if you're trying to use $_SERVER['REQUEST_URI']. It should be;

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

        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index /index.php;

        include fastcgi_params;
        fastcgi_split_path_info       ^(.+\.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;
    }

To get the controller name, just use the getter from the router service;

echo  $this->router->getControllerName();

When you call the handle(), it should be like this (how I do it on my nginx platform)

echo $objApplication->handle()->getContent();


570

Hi ! H!!

Thank you so so much!!!

I solved it with your advice!!



3.0k

Awesome! Glad to help :)

Hi ! H!!

Thank you so so much!!!

I solved it with your advice!!