Welcome Guest, Not a member yet? Register   Sign In
Custom URI Segments?
#1

[eluser]Jay Logan[/eluser]
Is there any possible way to allow custom URL titles that include segments - similar to how EE does? IE: allow a user/admin to input a desired URI such as "products/computers/apple" but have it route to a controller that reads the entire URI and pulls appropriate record from a database. Trying to build up my backend for easy SEO purposes.
#2

[eluser]n0xie[/eluser]
Yes. One of the ways is to make a lookup table which is just a table which holds virtual urls' and where to map them to. Then whenever a new requests comes in, you match the url against the lookup table, and load the aliased controller/function/library/w.e.

There are several examples posted on the forum.
#3

[eluser]Jay Logan[/eluser]
I get the idea of a look up table. I have something already in place for that. The problem is with the routing I guess. The custom URI's don't work because of CI trying to load certain functions that wouldn't exist. And I don't see how I could make a route to catch any possible combination. Any help? I've searched the forums.
#4

[eluser]mradlmaier[/eluser]
I used routes to have SEO friendly URL´s. That works nicely, but I just have a fixed set of routes, and just a few of them use simple regular expressions.

You probably want to be able to have kinda dynamically mapped URL´s, where the admin can add new categories or products in the future, right?
Principally, I think this could be possible with routes and regular expressions.
I admit, finding the correct regular expression is not trivial.
#5

[eluser]Jay Logan[/eluser]
So I think I have a decent solution. Tell me what you think.

Edited my routes to only include this:

Code:
$route['default_controller'] = "pages";
$route['scaffolding_trigger'] = "";
$route['(:any)'] = "pages";

In my pages pages.php controller, I added the _remap function like this:

Code:
function _remap()
{
    
    $view_file = $this->pages_model->get_view_file($this->uri->uri_string());
    $this->layout->view($view_file);
}

And basically I have a table full of URI strings that tell the function which view file to load. This is just what I could come up with so far. Tomorrow I will clean it up nice to check if URI strings exists in DB. And for some reason, it won't show URI string if segment 1 is "home". So I probably need to write something to check for that.
#6

[eluser]mradlmaier[/eluser]
Interesting approach. Cool. That way you could have an application, which kinda dynamically modifies itself? methods...




Theme © iAndrew 2016 - Forum software by © MyBB