Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A "1" ends up in the rendered markup when using this router #618

Open
leggettc18 opened this issue Apr 22, 2022 · 4 comments
Open

A "1" ends up in the rendered markup when using this router #618

leggettc18 opened this issue Apr 22, 2022 · 4 comments

Comments

@leggettc18
Copy link

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).

@compilekaiten
Copy link

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've been getting this as well, any chance you were able to figure out the issue?

@compilekaiten
Copy link

@DeveloperMarius Do you have any insight in this?

I'm using require_once to load my views/html.

@cdanielzt
Copy link

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;

@skipperbent
Copy link
Owner

skipperbent commented Feb 21, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants