Welcome Guest, Not a member yet? Register   Sign In
Creating a database-driven dynamic route **SOLVED**
#3

[eluser]Dean Rantala[/eluser]
**SOLVED**

This one needs to be a sticky.

Also suprised this is not a core feature.. but here we go:

1) Open system/libraries/Router.php
2) Around line 238 you will find "Can't find the requested controller"

This is our magic moment! Why.. oh why.. could the core devs not thing about letting you define a default "404 conntroller"?

3) Alter this:

// Can't find the requested controller...
show_404($segments[0]);

To look like this:

// Can't find the requested controller...
if( file_exists(APPPATH.'controllers/controllernotfound.php'))
{
$this->set_class('controllernotfound');
$this->set_method('index');
}
else
{
show_404($segments[0]);
}

Presto! Of coarse, you could get fancy and do a check to see if a default "404 controller" is defined in your config somewhere - but this gets the job done.

Now create a controllers/controllernotfound.php class and for the index method, do a "print 'it works'" or something to test.

You now have a central spot to test for a CMS page, perhaps run a Lucene search (for "page not found - but here are some similar search results"), or even just a really fancy 404 page.

Hope this helps

- Dean


Messages In This Thread
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-12-2009, 08:20 PM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-12-2009, 08:31 PM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-12-2009, 09:02 PM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 01:18 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 03:59 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 04:11 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 04:19 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 04:38 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 07:58 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 08:29 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 01-22-2010, 10:54 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 02-07-2012, 04:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB