HMVC custom 404 pages |
[eluser]CISCK[/eluser]
[quote author="kaola" date="1250138236"].htaccess ErrorDocument 404 /404.html[/quote] @kaola: Won't that redirect users to 404.html? The benefit to extending CI's 404 behavior is that you're still using the correct 404ed URL in the browser. [quote author="Dan Horrigan" date="1250147223"]Why go through all of this to show a 404 page when CI already does one? Simply modify the error_404.php file in the errors folder in the application folder. This is by far the easiest way to do it.[/quote] @Dan Horrigan: You're probably right, but this method doesn't allow you to route through a controller (without a redirect or breaking MVC). That's why I extend the CI_Router class like so. This technique solves the controller problem, but I can't figure out how to make it work with the show_404('page') method (in CI_Exceptions). Calling show_404 will use CI's default error_404.php view. Any thoughts? I do agree that there should be a better way though. [quote author="Mikle" date="1250154554"]My application has widgets and I use HMVC. I use main template with widgets and sitemap in content zone for 404 pages.[/quote] @Mikle: I have yet to try HMVC, so I don't really follow you. Does your method involve redirecting the URL at all?
[eluser]Mikle[/eluser]
[quote author="CISCK" date="1250546976"] [quote author="Mikle" date="1250154554"]My application has widgets and I use HMVC. I use main template with widgets and sitemap in content zone for 404 pages.[/quote] @Mikle: I have yet to try HMVC, so I don't really follow you. Does your method involve redirecting the URL at all?[/quote] My method redirects from error pages to 404 controller and output '404 error' header for search engines. In 404 controller I add: Code: header("HTTP/1.1 404 Not Found");
[eluser]renownedmedia[/eluser]
With most of my pages, every page has the same layout. Preferably, I'd like to display the error message within the content area of my main template file (while still sending the 404 header). That way, the user can still browse the website without having to use the history or change the URL.
[eluser]CISCK[/eluser]
I just came across this site with an nice solution. It only requires extending a single method from CI_Exceptions, and an additional controller method for routing (as you would for any other view). My example is slightly modified for my own purposes, so take a look at Kelvin's example too. libraries/MY_Exceptions.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); controllers/error.php Code: <?php Note that any time a user encounters a 404, or you send a 404 using the show_404 method, the URL will not change. For example, when a user goes to http://example.com/this-page-does-not exist, they will get a 404 error without being redirected to a different URL. This is the expected behavior for most users (and search engines). Thanks, Kelvin!
[eluser]Mikle[/eluser]
CISCK Change: parent::CI_Exceptions(); to: parent::__construct();
[eluser]asylmottaket[/eluser]
[quote author="wiredesignz" date="1247705235"] Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); Than you route the base_controller to something like "home", so you dont have http://localhost/base_controller/some_method in the url?
[eluser]Peng Kong[/eluser]
hi wiredesignz, how do we use your base_controller? do we just simply extend base_controller instead of controller?
[eluser]hot_sauce[/eluser]
Create new file "MY_Exceptions.php" in application/core and paste this Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Create new file "Exceptions.php" in third_party/MX/ and paste this Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); application/"modules"/"mysite"/errors/error_404.php and in your modules folders create a "errors "folder with your error_404.php file |
Welcome Guest, Not a member yet? Register Sign In |