Welcome Guest, Not a member yet? Register   Sign In
Extended CI_Router class (allows fallback/catchall controllers)
#1

[eluser]Dean Rantala[/eluser]
So here you are building a CMS, blog, etc..

Ideally, in the case of a CMS you would have your system check for the existence of an actual (real) page (well, controller/function). If the real page does not exist, THEN you fall back to checking the CMS/Blog/etc.

This customized Router class does just that. Essentially, it allows you to define a "fallback controller/function" that is always called when the incomming request does not match a valid controller/function. In this way, you can have much more inteligent 404 controllers, or in the case on an integrated CMS, you can now check to see of the request matches a valid CMS page before throwing a 404.

Installation: simply download and stick the MY_Router.php file in your application/libraries directory.

Configuration options: In your application/config/routes.php, add the following option to activate the catchall controller

$route['catchaall_controller'] = 'my_catchall_controller';

Now under your application/controllers directory, create a "my_catchall_controller.php" controller. All requests handed to this new catchall controller will call the index() function. Additionally, to access the original request URI, you will do so via the $this->uri->rsegment(x) method (the $this->uri->segment() method will return the catchall controller itself).
#2

[eluser]Unknown[/eluser]
我想看一下你写的源码,可是这里不能下载了,你能把资源再放一次吗?或是把MY_Router.zip发到我的邮箱也可以,谢谢了。邮箱是[email protected]




Theme © iAndrew 2016 - Forum software by © MyBB