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.

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.



386

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



42.2k
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;
});


386

Just switch to:

``` $router::URISOURCESERVERREQUESTURI ```

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

```php $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 !



386

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