Welcome Guest, Not a member yet? Register   Sign In
Several segments in the URL
#1

[eluser]tobbesanda[/eluser]
Hi there folks!

I'm building my first (larger) site using CodeIgniter and I think it's really great! But I seem to have a little problem with how I should do to fix my URL's.

I have a blog with categories and would like my single page look something like this:

http://mysite.com/category/music/the-actual-post

How can I do this?

Thanks
Tobias
#2

[eluser]überfuzz[/eluser]
[quote author="tobbesanda" date="1253913073"]Hi there folks!

I'm building my first (larger) site using CodeIgniter and I think it's really great! But I seem to have a little problem with how I should do to fix my URL's.

I have a blog with categories and would like my single page look something like this:

http://mysite.com/category/music/the-actual-post

How can I do this?

Thanks
Tobias[/quote]
Depends on what functionality you're looking for. CI is set to work like this: www.mysite.com/controller/method/etc/etc
You can have a controller called radio. The controller(radio) has a function called music and the function music uses segment(3), segment(4) and so on as a parameters.
#3

[eluser]tobbesanda[/eluser]
I store my categories in my database so I can't use a method like music.
#4

[eluser]überfuzz[/eluser]
[quote author="tobbesanda" date="1253913965"]I store my categories in my database so I can't use a method like music.[/quote]
Before you start with some fancy alteration... Could you explain what you're going to do? Not to be nosy or any thing, but we might find a way of structure your site the CI way.
#5

[eluser]tobbesanda[/eluser]
Just think that I have a normal blog with the url:

http://mysite.com/category[1]/category-1[2]/category-1[3]/my-blog-post[4]

category[1] = the controller
category[2] = a parent categories from the db
category[3] = a child category (if exists) from the db
my-blog-post[4] = The blog post that is stored in the db and belong to category[2] & category[3] (if there is one)
#6

[eluser]BrianDHall[/eluser]
The easiest way I can think of is to use routes to remap category[1] to category_controller/category[1], then in the index() function of that controller you use the last segment of the URI to determine the post, and then either the rest of the URI is just SEO/navigational filler or you can use it for whatever you want.

If you only want certain URLs remapped then the best practice would be to use some small bit for regex, like the category would be cat-rock or cat-classical - then you could only regex on cat- to avoid remapping everything to one controller.

If you want you can then use index - or the constructor - to then call the page function of the controller based on something in the URI, but it depends how you want to build it.

Its a little hacky and it changes how CI works, but it would work.




Theme © iAndrew 2016 - Forum software by © MyBB