Welcome Guest, Not a member yet? Register   Sign In
Any Help Appreciated (Rerouting/Remapping) :)

Hello all,

Basically, here's what I'm looking to do:

I'm working with URLs to determine a page (obviously), and have the URLs set up in the following way:

This currently checks the database to see if segment 1 exists in the database as a page slug, and loads the page if so. So far, so good. Note: I'm handling this in the index() method on the main controller and using the following route in routes.php:

$route['(:any)'] = "index";

Here's the problem though. I also have controllers that need to be handled, such as /admin. Obviously, it's checking the db for a page with a slug "admin", and not finding it (which it shouldn't). What I need it to do is this:

Check db, if slug exists, load page from db;
If slug does not exist in db, check if there's a controller for it and load that instead (using CI's default handling of controller/function in URI);
Else load 404.

I suspect that there's a way to do this using _remap(), but I don't really understand how it works or what I need to do to get it going.

Thanks for any and all help and suggestions!


Nevermind, got it (found it on Stackoverflow), but please let me know if I'm doing this the correct way, or if there's a better way. In routes.php:

$route['default_controller'] = "index";
$route['admin'] = 'admin/index/';
$route['admin/(:any)'] = 'admin/$1';
$route['(:any)'] = "index";
$route['404_override'] = '';

I am not using _remap(), but I feel like maybe I should be? Regardless, it seems to be working how I need it to for now, at least int he most basic sense, but I'm not sure how easily it will scale.

[eluser]Lewis Cowles[/eluser]
Hi there,

It sounds like you have a square peg and a round hole. If for example you changed from using your index page to another method, it can take the parameters as url variables; Using these parameters to query the database seems like a simple solution to me, if your goal was to build those pages from the database.

You do need to be careful to build a solid abstraction layer however, because otherwise unscrupulous individuals may find exploits to query alternative data from your systems database. Also an open-ended system like this can have lots of holes and flaws so really, I wouldn't advise it.

function dbpage($field,$constraint1,$constraint2)
    $chk = $this->db->get_where('dbpages',array('somecolumn'=>$constraint1,'anothercolumn'=>$constraint2));
    if($chk->num_rows == 1) // valid, now build page
        //do stuff here

Btw these methods can be used for /admin or /anything really as the methods live inside the main controller, be careful though, there is not much more reason to having one of these than having another controller

Theme © iAndrew 2016 - Forum software by © MyBB