Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
[404 PAGE] - How to redirect to the 404 page ?
  • Hello dude, I try to understand the 404's page functionnement.
    I duplicate and rename the 404's file for my Object Norms.
    So I create in : - fuel/app/classes/controller/norms.php :
    Method action_404() : 
    public function action_404(){
     return Response::forge(ViewModel::forge('norms/404'), 404);
    }
    

    - fuel/app/classes/view/norms/404.php :
    <?php
    class View_Norms_404 extends ViewModel
    {
     public function view()
     {
      $messages = array('Norms1', 'Norms2', 'Norms3', 'Norms4', 'Norms5');
      $this->title = $messages[array_rand($messages)];
     }
    }
    

    - fuel/app/views/norms/404.php :
    Just for this test, I cut-paste like welcome file.
    Now I want test : - http://127.0.0.1/fuel_web/website/public/index.php/norms/404
    -->it's Ok. In my Controller Norms, I have a function action_index($id=NULL).
    I want test my variable $id, if null I want to be redirect in the norms/404.
    if(!is_null($id)){
     $this->template->content = View::forge('norms/views',$data);//Chemin d'accès
    } else {
     $this->action_404();
    }
    

    - http://127.0.0.1/fuel_web/website/public/index.php/norms I have this error.
    [b]
    ErrorException [ Notice ]: Undefined variable: content
    [/b]
    

    I just want, if my variable is null, to be redirect in 404's page. How do it ? Thanks Djik
  • Have you changed the app/config/routes.php _404_ variable? I normally just do throw new HttpNotFoundException; And it'll present me that 404 page!
  • I find. I replace this code :
    if(!is_null($id)){
       $this->template->content = View::forge('norms/views',$data);//Chemin d'accès
      } else {
       Response::redirect('norms/404');
      }
    

    And now, if $id is null, I redirect to my 404 page of my object Norms
  • Moved to General, this is a question, not a "tip or tutorial"

Howdy, Stranger!

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

In this Discussion