Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Uri Class returns 404 url
  • Not sure if this is normal, i have my 404 function in app/classes/controller/welcome.php I then throw a 404 from a module using throw new \HttpNotFoundException; now when Uri::current() is called, it is returning http://test.com/welcome/404 and not the actual requested url. Uri::main() returns the actual requested url, but Uri::segments() is returning controller 'welcome' and method '404'. So not sure, is it supposed to return the 404 url? At the moment I have to use this sort of approach to rectify: $uri = Uri::main();
    $uri = str_replace('http://', '', $uri);
    $uri = str_replace('https://', '', $uri);
    $uri = explode('/', $uri);
    array_shift($uri); return Uri::create( $new . '/' . implode( '/', $uri ) ); Thanks! apologies if this is a obvious question.
  • From the framework point of view, not finding what was requested is an exception. How this exception is handled is up to the application. There is no specific 404 handling within the framework. By default, the exception is caught in your index.php, and if caught, it will forge() a second request for the 404 route. So from a code point of view, it's a new request (like an HMVC request), which is why you get these results. The Uri class is context aware, because it needs to support nested requests. So it returns information based on the active request, not on the main request. You can access the main request URI object directly using
    $mainuri = \Request::main()->uri
    

    on this object you can use get(), get_segment() and get_segments().

Howdy, Stranger!

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

In this Discussion