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

Pass _url parameters to the url!!

Hi, friends! I was a novice and I can not speak English. So, All sentences are translated by Google. :)

There is a question I feel very confused, is when I pass _url parameters to the url, the entire route resolution is not correct. Does that mean I can not pass the _url as a parameter in the url? Or are there other solutions? I do not know if anyone can understand the English translation by software.

Request parameter _url is used for routing purposes, choose another parameter if you want everything work properly.



1.4k

Request parameter _url is used for routing purposes, choose another parameter if you want everything work properly.

If I have a URL like this: /product?category=1&show=table. This page is used to display the list of products.

When the user manually add a parameter to the end of the URL, like this:/product?category=1&show=table&_url=xxx This page will jump to the 404 page.This will make people feel very strange, the whole URL paths are not changed, but the page has to jump to 404



79.0k
Accepted
answer
edited Apr '16

Just switch to:

$router::URI_SOURCE_SERVER_REQUEST_URI

In your services.php IoC, this is working definition for router service/component:

$di->setShared('router', function () use ($di){
        $router = new \Phalcon\Mvc\Router();

        //we're using Front Page Controller pattern in relation from nginx -> Phalcon
        $router->setUriSource($router::URI_SOURCE_SERVER_REQUEST_URI); // Use $_SERVER['REQUEST_URI']
        //Set whether router must remove the extra slashes in the handled routes
        $router->removeExtraSlashes(true);
return $router;
});


1.4k

Just switch to:

$router::URI_SOURCE_SERVER_REQUEST_URI

In your services.php IoC, this is working definition for router service/component:

$di->setShared('router', function () use ($di){
       $router = new \Phalcon\Mvc\Router();

       //we're using Front Page Controller pattern in relation from nginx -> Phalcon
       $router->setUriSource($router::URI_SOURCE_SERVER_REQUEST_URI); // Use $_SERVER['REQUEST_URI']
       //Set whether router must remove the extra slashes in the handled routes
       $router->removeExtraSlashes(true);
return $router;
});

Thanks !



1.4k

Thanks for upstairs friends.

If I directly use router->setUriSource($router::URI_SOURCE_SERVER_REQUEST_URI);. It will cause the router to resolve the entire URL path for the project directory. In the absence of virtual host configuration, it will go wrong. So I changed it to this:


define('APP_WEBPATH', str_replace('\\', '/', '/'.
    trim(str_replace(realpath($_SERVER['DOCUMENT_ROOT']), '', realpath(APP_PATH)), '\\/') ) );
$router->handle(str_replace(APP_WEBPATH, '',$_SERVER['REQUEST_URI']));

It works fine