simple-php-router
simple-php-router copied to clipboard
A "1" ends up in the rendered markup when using this router
I have a simple PHP site I was modernizing (mostly just to see if I could). I found this routing library that seemed good and I wanted to replace the one I wrote because this one seemed better. However, when I added it in, everything routed correctly, but I got the number "1" appearing in the markup of every page, just before the end of the body tag. When I switched back to my custom router it went away.
Here is the source code to the project in question. src/routes.php contains the routes, public/index.php is the main index file. Also I was using php -S 0.0.0.0:80 -t public/ to serve the app in development if that's important (didn't want to have to set up a whole Apache/Nginx server in docker in order to develop the app. Reconsidering that lately but this should probably work correctly with PHP's built-in server regardless).
I have a simple PHP site I was modernizing (mostly just to see if I could). I found this routing library that seemed good and I wanted to replace the one I wrote because this one seemed better. However, when I added it in, everything routed correctly, but I got the number "1" appearing in the markup of every page, just before the end of the body tag. When I switched back to my custom router it went away.
Here is the source code to the project in question.
src/routes.phpcontains the routes,public/index.phpis the main index file. Also I was usingphp -S 0.0.0.0:80 -t public/to serve the app in development if that's important (didn't want to have to set up a whole Apache/Nginx server in docker in order to develop the app. Reconsidering that lately but this should probably work correctly with PHP's built-in server regardless).
I've been getting this as well, any chance you were able to figure out the issue?
@DeveloperMarius Do you have any insight in this?
I'm using require_once to load my views/html.
I managed to fixit by adding an exit after requesting a file, the problem is that the return is printed.
return require 'login.html';
to
require 'login.html';
exit;
That's because the default behavior of the router is to render multiple routes until an output is returned.
In your case, you can disable this feature, then you don't need to use the exit.
Set the setRenderMultipleRoutes to false before you start the routing, like so:
Router::router()->setRenderMultipleRoutes(false)->start();
I think that should work. If not then you can always just return true.