Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Routing don't work well when using named parameter and throw HttpNotFoundException.
  • I met serious routing bug. When I used named paramer in routes.php and throw HttpNotFoundException, don't route to 404 action. I made small sample. try it. app/classes/controller/test.php :
    <?php
    
    class Controller_Test extends Controller &#123;
    
        function before() &#123;
            Debug::dump($this->request->route);
        }
    
        function action_index() &#123;
            echo 'Here! our home!!';
        }
    
        function action_404() &#123;
            echo 'Oppps, page not found!';
        }
    
        function action_test() &#123;
            throw new HttpNotFoundException;
        }
    
        function action_1() &#123;
            echo 'Pass 1';
        }
    
        function action_2() &#123;
            echo 'Pass 2';
        }
    
        function action_3() &#123;
            echo 'Pass 3';
        }
    
    }
    

    app/config/routes.php
    <?php
    
    return array(
        '_root_' => 'test/index', // The default route
        '_404_' => 'test/404', // The main 404 route
    
        'test' => 'test/test',
        ':a/:b/:c' => 'test/3',
        ':a/:b' => 'test/2',
        ':a' => 'test/1',
    );
    

    and go domain/public/test, it go test/2 pattern. When named parameters deleted, it go 404 routing. Please help me. P.S. Also, numeric characters can't use in named parameter. If used, an error happen. Maybe it is not OK. Accept numeric characters or kick more proper error message or write it on documents clearly. It is hard to find.
  • Thx for answer. I hope if I throw this exception, route to 404 page automatically. Because your documentation about 404, say 'Fuel will exit for you once it has run the 404 page. ' http://docs.fuelphp.com/general/error.html It never say 'need hack to index.php' ;) I never write this docs. Just the docs say 'run the 404 page'. So, I said it is bug must be correct. If you can't correct soon this, let me know how hack index.php. I'm not expert for PHP and FuelPHP framework. ML.
  • There is no question of hacking. The index.php contains the try / catch block that catches and processes the HTTPException. If it is caught, it retrieves the _404_ route, and forges a new Request object using the defined route as URI. And by default, new HTTP requests are routed. FuelPHP does protect against routing loops (a 404 that causes a 404), but not against the fact that your 404 URI is routed elsewhere. As I wrote, if you don't want this behaviour, open your index.php, look for "Request::forge($route)->" in the catch block, and replace it by "Request::forge($route, false)->". This is new behaviour in v1.1, so I guess that whoever wrote this didn't update the docs (properly). Please create an issue for this on http://github.com/fuel/docs/issues so someone can pick this up...
  • Thx, ic. The reason I post my bug report here, I read : http://fuelphp.com/blog/2011/12/version-1-1-finally-lands, this said about open-an-issue. But this link route to document page, not issues page on github. (So, I spend half hour to find my miss, I doubted my setting of github... :D ) And this blog also said post in here when I have tourble. ;) Wel...I must also post this blog as issue to github??? :D And back to my work, I understood it changed in 1.1. and now it move correct. It prevent to loop 404 to 404... ummm, I think it never solve the loop problem. How about "a ':a/:b' pattern that causes a 404" ?? It don't loop??
  • No, it doesn't, FuelPHP detects it's seen the same route twice. And I've updated the documentation to highlight this issue.
  • You don't describe what happens and what you expected to happen, so this is a bit guess work. But I assume your issue is the 404 route? The exception is handled in your index.php file, where a new request is forged using the _404_ route. As this is a normal request, FuelPHP will route this request, and "test/404" will match your ":a/:b" route, and will display "Pass 2" instead of "oops not found". If you don't want 404 route parsing, change "Request::forge($route)" in your index.php to "Request::forge($route, false)". And the action_404 method will be called correctly.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion