• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[RESOLVED] module/function/id -> to -> module/function/title ?

#1
[eluser]Wattswing[/eluser]
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 :
Quote:http://localhost/ci_test_base/portfolio/work/29

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 :
Quote:http://localhost/ci_test_base/portfolio/work/title_of_the_item_29

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.

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

#3
[eluser]Wattswing[/eluser]
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.
Like
Code:
http://localhost/ci_test_base/portfolio/work/my-title-I-would-like-to-give_29

?

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

#4
[eluser]WanWizard[/eluser]
Yup.

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.

#5
[eluser]Wattswing[/eluser]
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.