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

Routing Bug with PHP Built in Server

Hi,

In my PHP Phalcon 3 Application I have a custom route:

$router->add("/{chapter}/{name}.{type:[a-z]+}", array(
    "controller" => 'images',
    "action" => 'getFile',
));

I test the application local with PHP Builtin Server, other routes are working regulary. If i test the route above: https://localhost:8000/XYZ/test.jpg I always get a 404. But in regards to the documentation it should work: https://docs.phalcon.io/en/latest/reference/routing.html

Do you have any idea whats wrong?

This is my .htrouter for the php built in server:

 <?php

if (!file_exists(__DIR__ . '/' . $_SERVER['REQUEST_URI'])) {
      $_GET['_url'] = $_SERVER['REQUEST_URI'];
 }
return false;

In production i use Nginx but it would be easier if I could use the built in server for local development



11.6k

maybe it's related to file permission, rather than routing problem?

Don't use the .htrouter, just change the source of the url:

$router->setUriSource(
    Router::URI_SOURCE_SERVER_REQUEST_URI
);

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

@lajosbencz: Exactly. It's always better to use Router component which will read data from $_SERVER["REQUEST_URI"].

.hrouter is not even being generated on latest DevTools.



7.5k
edited Oct '16

https://docs.phalcon.io/en/latest/reference/built-in.html

Latest documentation doesn't reflect the routing fix indicated here.

-- edit

Is this something that needs to be toggled on just for the PHP dev server, or is it safe to leave in production?