Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Returning 404 status when using Controller_Template
  • I'm using the Template controller to display my 404 page, what's the best way to return a 404 error?
  • Thanks Harro!
  • In your action method:
    return \Response::forge($this->template, 404);
    
  • hello, I'm trying to upgrade from fuelphp 1.2 to fuelphp 1.3.
    In version 1.2 I used in action_index() of a class which extends Controller_Template:
    $this->response->status = 404
    

    for version 1.3 I replaced it with Harros code. The template is shown, but the status is 200 and not 404.
    Harro Verton wrote on Friday 17th of August 2012:
    In your action method:
    return \Response::forge($this->template, 404);
    

  • Does your controller have an after() method that might interfere with this? With the standard after() method in Controller_Template, if your action returns a Response object, it will use that instead of creating it's own. It looks like in your case the return value is ignored. You can easily test that by returning a differerent response:
    \Response::forge('something different', 404);
    
  • Thank you Harro for your fast and helpful post. In used another action function in my Controller_Template like this:
    public function action_x()
    {
       $this->action_index();
    }
    

    and in action_index() I used
    return Response::forge($this->template, 404);
    

    I forgot to return the Response in action_x, now it works:
    public function action_x()
    {
       return $this->action_index();
    }
    

Howdy, Stranger!

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

In this Discussion