Custom, database-driven 404 page -- can this be improved? |
[eluser]arlodesign[/eluser]
Using the code from this forum post, I was able to pull off something I really wanted from my CodeIgniter application: if the first segment of the URI doesn't have a matching controller, send the request to a page controller and check for content in the page database. I did it by extending the Router.php library, as described in that post, and changing _validate_requests() as so: Code: show_404($segments[0]); became Code: return array('page', 'index', $segments[0]); Here's my page controller: Code: class Page extends Controller { Here's where it gets interesting and I turn to you: I also wanted the content of my 404 page stored in the same pages database table so it could be edited by a user in an admin panel. So I created MY_Exceptions.php: Code: class MY_Exceptions extends CI_Exceptions { My question to the always brilliant CodeIgniter community: My solution to this 404 thing feels like a total hack. I had to manually invoke the output class to get the views to appear and, worst of all, I had to reuse an entire block of code which I would have to change in two places should I need to make adjustments. Any ideas on how I could improve on this idea? Can I actually call the page controller from the library item, or is that a terrible idea? UPDATE: It should also be noted that, while I'm not a total n00b, my programming skills are somewhere between novice and intermediate. I apologize now if I follow up your kind answer with a bunch of seemingly stupid questions. Thanks. ANOTHER UPDATE: Fixed link to forum post in first paragraph. |
Messages In This Thread |
Custom, database-driven 404 page -- can this be improved? - by El Forum - 07-13-2008, 07:42 PM
Custom, database-driven 404 page -- can this be improved? - by El Forum - 07-14-2008, 08:42 AM
Custom, database-driven 404 page -- can this be improved? - by El Forum - 07-14-2008, 09:24 AM
Custom, database-driven 404 page -- can this be improved? - by El Forum - 07-14-2008, 10:49 AM
Custom, database-driven 404 page -- can this be improved? - by El Forum - 07-14-2008, 10:53 AM
Custom, database-driven 404 page -- can this be improved? - by El Forum - 07-14-2008, 10:56 AM
Custom, database-driven 404 page -- can this be improved? - by El Forum - 07-14-2008, 11:01 AM
Custom, database-driven 404 page -- can this be improved? - by El Forum - 07-14-2008, 11:09 AM
Custom, database-driven 404 page -- can this be improved? - by El Forum - 07-14-2008, 03:51 PM
|