3

My URL adress looks like this:

/blog/topic/6/test

can it be changed like this:

/blog/topic/test

I'm using CodeIgniter 2.x

9
  • 2
    yeah sure :) but please explaing when you want to change to url; do you want the url /blog/topic/test to be equivalent to /blog/topic/6/test (which sounds a bit odd to me because you can probably not identify the right topic anymore, unless test is a unique name), or do you want to just filter out the number after someone already reached the controller by requesting the first version of your url? In that case, depending on the strictness of the syntax of your url, an explode() or a call to a regex function would do Commented Feb 24, 2012 at 11:03
  • I just want to hide the id in the url - in this case (6), but it can be another number. Also I use it as a method's parameter and this method uses it. Commented Feb 24, 2012 at 11:07
  • 1
    well the problem here is that you need the id somehow to designate the right post. So this can only be done if either the string test is a unique identifier, so you could do something like SELECT * FROM your_table WHERE topic_slug='test' or if you have saved the id already in a session. Because php can do alot, but not magically read the user's mind to fetch the desired topic :) Commented Feb 24, 2012 at 11:09
  • 1
    well then, if 'test' is the topic title you have a chance, but then you have to make the title unique, which is most of the times not desirable. Otherwise, to make it look a bit sweeter you can turn them around (title and id). Commented Feb 24, 2012 at 11:25
  • 1
    well wordpress creates unique slugs; when you have title like This is my blogpost, it converts it to this-is-my-blogpost, saves it in a unique mysql cell and looks it up when needed. When you have two of the same titles, you could convert the slug, as it's called, to this-is-my-blogpost-2 or something like that. Think of your own logic for handling that type of situations. But it can be done if you add a new column in your database! Commented Feb 24, 2012 at 11:32

1 Answer 1

1

Yes, the 6 is just the GET parameter - you can use POST instead!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.