Trying to get 404 to work

edited August 2014 in Installation
HI, I have been using this for about 3 years. I have not upgraded much as I have too much invested in it. I have version .9.3.
The issue right now is say I have a site.com/test and test is not a controller and I want it to show a 404. I have the Opt-In working fine. If I set development mode it shows blank page obviously. Otherwise I get errors that it cant find a page to go to. I am sure it is something simple. I cant find where in the code it kicks it to a 404. 404 override is the page_router so the 404 never seems to get called even though test controller does not exist. test test1 whatever. I have custom error page I go to in my htaccess but that is for shtml that I catch. This will be for errors like I cant find a page or the controller. It errors out in the header:
Message: Undefined property: CI_Exceptions::$load
Filename: _blocks/header.php
I always know that means I dont have the view file set. In this case there is no controller correct or any view file matching it. I know I must have something simple to set. fuel_mode is cms.
Well let me know.. I think I have given enough info.

Comments

  • edited September 2014
    If you are using an "opt-in" view file to create a page, it will use the fuel/modules/fuel/controllers/fuel_router.php controller. If you check out that controller, you'll see that it first checks the CMS for a page (if fuel_mode is set to "auto"), then it will check for a view file named "test". If that view file exists, it will get pulled into a layout file (the default is the fuel/application/views/_layouts/main.php file). That layout file usually has called to load in the header and footer view files which may be where that error is coming from. If that view file does not exist, then it will do a redirect_404 which will first check for any matching redirects and if none are found, it will finally 404 out.
  • edited August 2014
    Hi, yes thanks for the help. I have it pulling the main.php default layout file. It does error on the header. Now I load the header in the view files.. first the layout then the header. But I see the layout main.php pulls in the header and footer for you. the pages get messed up if I do not pull in the layout, header, and footer in the view page. I just assumed the controller check would happen before it pulled in the header. So what am I doing wrong? I have a huge app and I can change it, just not sure. I mean if I am pulling in the header and footer in the view then why need the layout? But more importantly I don't think I use opt-in views much I think I have a controller for everything. Maybe one or two I do not. I have some advanced modules from a previous code helper but I do all simple modules and I am happy with it. So what do I do to get the 404 check before it calls the layout? I will check out the fuel_router controller. OH, I see I do not have a fuel_router.php file.. I see fuel\modules\fuel\config\fuel_routes.php

    ok to clarify I have this at the top of my view files.
    <?php fuel_set_var('layout', '')?>
    <?php $this->load->view('_blocks/header')?>

    Does it load main.php or nothing at all. Maybe none.php? Why is it trying to load a header if it can't find the controller? I load all the head and footer and content in the view file itself. But if I do not put that code above then the view page gets all jacked. I sometimes load different headers depending on my needs in the view file. I don't have php debugging setup as I really never need it but times like these. Well back to the question.. how to get a 404 to show?

    if it helps this is how I load it from the controller but since it should not get to a controller I don't think this helps a lot.:
    $vars['page_title'] = 'xxxxxx';
    $this->load->module_library(FUEL_FOLDER, 'fuel_page', array('location' => 'xxxxxxxxx'));
    $this->fuel_page->add_variables($vars);
    $this->fuel_page->render();
  • edited 9:39AM
    If you are pulling in the header and footer in your view, then you don't need a layout and you add exactly what you have at the top of your view file to not have a layout. If you don't want the main layout to be their by default, you can change it in the fuel/application/views/_variables/global.php file.

    Also, fuel_router exists in the "fuel/modules/fuel/controllers/fuel_router.php" file path (I mistakenly did not have "controllers" in the path above and have since updated).
  • edited September 2014
    Ok, that is good I have the layout set correctly. I have searched my entire directory and fuel\modules\fuel\controllers\fuel_router.php does not exist in my copy.. It is 0.9.3.. are you thinking of an updated version? As I still don't have any idea how to fix this as a it never flags a 404 and it should.. was there an error in this version?

    Are you thinking of page_router.php? That exists.

    Ok, yes that is the file.. I am seeing it is calling a 404.
    It is happening in the show_error function.
    include(APPPATH.'errors/'.$template.EXT);
    When that runs it is causing it so I will hunt it down and see. Likely header is getting called as you said.

    Yep, its the error_404.php file and whenit calls the header I have a lot in there like checking if they are logged in so now I can deal with it.. thanks. Appreciate your help.

    I hope this helps someone else. I have done a huge amount on this CMS although I do not use the admin at all, I have made my own admin. Added roles and permissions and such and have run into similar issues but this one I could not figure it out.
  • edited 9:39AM
    I'm sorry, it's called page_router and not fuel_router (old name of it).
  • edited 9:39AM
    Thanks. You got me pointed in the right direction and I am resolving the problem. I may upgrade to the newest version at some point but not critical right now.
Sign In or Register to comment.