silexphp / Silex

[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components
https://silex.symfony.com
MIT License
3.58k stars 718 forks source link

GET "/" in a ControllerCollection #184

Closed fredr closed 12 years ago

fredr commented 13 years ago

When adding a ControllerCollection, and mounting that to let's say /test and the adding a path to "/" in that ControllerCollection, I get NotFoundHttpException: No route found for "GET /test/" when trying to access www.addresstomy.app/test/

But when I add a path, lets say /yes to my ControllerCollection, accessing www.addresstomy.app/test/yes will work

I've put together a little test below, it's been tested on f400c25 and 535c1cb, accessing /test works fine in f400c25, but not in 535c1cb

If I remove the "/" route that is defined in index.php (www.addresstomy.app/) below, /test/ will work in the new version of silex as well.

Working version Silex version f400c25 2011-09-22 11:05:30 +0200

Non working version Silex version 535c1cb 2011-10-09 11:28:30 +0200

This is my example app

index.php

$app = new Silex\Application();
require_once __DIR__ . "/TestControllerProvider.php";

$app->get("/", function() use($app) {
    return "this breaks it..";
});

$app->mount("/test", new Test\TestControllerProvider($app));

TestControllerProvider.php

    namespace Test;

    use Silex\Application;
    use Silex\ControllerProviderInterface;
    use Silex\ControllerCollection;

    class TestControllerProvider implements ControllerProviderInterface
    {
        public function connect(Application $app)
          {
                $controllers = new ControllerCollection();

                $controllers->get("/", function() use ($app) {
                    return "this wont work";
                });

                $controllers->get("/yes", function() use ($app) {
                    return "this will work!";
                });

                return $controllers;
          }
    }
fredr commented 13 years ago

or is it me doing something crazy here?

olivierphi commented 13 years ago

It doesn't work for me either, whether I use the latest "phar" version (Silex version 535c1cb 2011-10-09 11:28:30 +0200) or the Git master branch up-to-date files... However, it really seems to be the correct use of ControllerProviderInterface ?

mgatto commented 13 years ago

Its most likely because you have defined a route for "get /" before you mounted "/test". Just move the mounting code to the beginning of index.php. This is how I've done it and it works for me.

That said, what you're describing does seem to be a sort of buggish behavior.

olivierphi commented 13 years ago

I tried what you explained, and it still doesn't work for me. Strange... :-/

fredr commented 13 years ago

Me too, what version of silex are you using @mgatto ? Does my code differ in any other way from yours?

romainneutron commented 12 years ago

I think @fredr and I got the same problem :

https://github.com/fabpot/Silex/issues/189

olivierphi commented 12 years ago

Yes indeed, this is probably the same bug ! :-)

olivierphi commented 12 years ago

This bug has been fixed by @igorw in ef75e13b62 ; it can be closed.

fredr commented 12 years ago

Then I'll close it! Thanks!