Hi,
I have a question... my site has a combination of CMS pages and controller pages. Now I want to establish a custom 404 page, because on calling a non existing page at the moment the CMS tries to build a page. I have debugged the thing and the call is not routed into my layout libraries. The strange thing is that the page loads my header.php but no file where I have included that file is not run through...
Do you have a hint for me where to start debugging?
Comments
Have I configured something wrong? From my understanding the 404 override should have happened earlier...
Put your custom code in there.
The 404 route is configured in ./config/routes.php
config/routes.php says $route['404_override'] = 'fuel/page_router';
;-)
And I am wondering why it results in the page router :-)
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Error extends CI_Controller { public function error404() { $this->fuel->pages->render("404notfound", $data, array('render_mode' => 'cms')); } } /* End of file error.php */ /* Location: ./application/controllers/error.php */ ?>
and my routes.php says
$route['default_controller'] = 'homepage'; $route['404_override'] = 'error/error404'; $route['admin'] = 'fuel';
On calling a non existing url I get the error
An Error Was Encountered
Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.
$route['404_override'] = 'error';
I have 2 layouts in my CMS. The main layout for simple cms content pages and a module layout for more custom pages generated on base of simple modules in the cms.
All pages now are redirected to the error page, although they are existing in the cms.
$this->locate does not return anything for the given segments, because the cms routes are not loaded into $this->routes
if (!array_key_exists(uri_path(TRUE), $this->fuel->pages->cms()) && uri_path(TRUE) != "offline") { $this->location = "404notfound"; } else { $this->location = uri_path(TRUE); }
For my installation this works, because the offline page is the only page generated in view_mode.
But this is not the whole solution... this does not take into account urls with a / at the end and the module detail pages with the id as suffix are not recognized correctly...
I think I need to spend some more thoughts into this ...
I want to achieve the following:
1. all non existing pages should be redirected to 404 cms page
2. all existing pages should be recognized no matter if the url is http:///page or http:///page/
3. all non existing detail pages (if the user enters a non existing ID into the url) should produce a readable result
I think 3. can be achieved in the models of the corresponding model... am I right?
if (!in_array(uri_path(TRUE), $this->fuel->pages->cms()) && uri_path(TRUE) != "offline") { $uri_path = uri_path(TRUE); if (substr($uri_path, -1) == "/") { $uri_path = rtrim($uri_path, "/"); } elseif (is_numeric(substr($uri_path, strrpos($uri_path, "/") + 1))) { $uri_path = rtrim($uri_path, substr($uri_path, strrpos($uri_path, "/"))); } if (!in_array($uri_path, $this->fuel->pages->cms())) { $this->location = "404notfound"; } else { $this->location = uri_path(TRUE); } } else { $this->location = uri_path(TRUE); }
in the file my_page_router function _remap($method).
http://docs.getfuelcms.com/modules/simple#post_pages
Note that in the example there is a 'empty_data_show_404' parameter you can use to
my module config looks like
$config['modules']['missions'] = array( 'module_name' => 'Einsätze', 'instructions' => lang("einsatz_instructions"), 'permission' => 'missions', 'item_actions' => array('save', 'view', 'publish', 'activate', 'delete', 'duplicate', 'create') );
The overview and detail page are generated via the layout _module.php
Is a usage of the empty_data_show_404 parameter also possible in this case?
the problem was that the fuel redirect for 404 expects a page named 404_error in the cms. My paged was named different...