Welcome Guest, Not a member yet? Register   Sign In
[RESOLVED] module/function/id -> to -> module/function/title ?

Hi everybody,
I'm pretty new in CI's practice.

I read a lot of topics that nearly approach my expectations but none directly explain the howto.

My site's URI work like that :

I ever put off the index.php with the .htaccess, and it works perfectly in local for now.

So I have a controller/function/id way of accessing the data.
But I'd like to catch the ID element's title, parse it (myabe with the url_title()'s URL helper) and rewrite it instead of the ID's segment like :

The more I read about URL rewriting through .htaccess, the more I think my "title_of_the_29_item" data is near of my model/controller methods.

So is there any way of retrieving this $title and send it to .htaccess in order to rewrite the URI properly ?

Thanks very much.
I hope my question is out of any trouble,
and don't hesitate to ask me more for anything.

Use a regex route:
$route['portfolio/work/(.*)_([0-9]*)'] = 'portfolio/work/$2';
which will match any string followed by an underscore followed by a number

Very smart.
So it would imply that I change my base list of items (that would make you land on the /29) and its URI.


Nice way of escaping the problem indeed Wink
And thanks a lot !


I haven't checked the regex completely, so see what the behaviour is if the segment doesn't end with a number. You might have to change it.

In fact the controller redirect to the index if the module's param' return something not defined as what it expects.
So nice way of dealing with url rewriting/routing in ci.
U should make a tuto of this small procedure.

Thanks a lot again for your fast reply ! Smile

Theme © iAndrew 2016 - Forum software by © MyBB