Welcome Guest, Not a member yet? Register   Sign In
Represent menu structure of website in urls ...
#1

[eluser]mvdg27[/eluser]
Hi guys,

I'd like to run a conceptual question by you, as I've been in doubt on what to do for several days now Smile

The situation is like this:

I have a CMS that allows you to create a tree-like structure of pages in a website as such:

id|parent|age|label
1|0|1|page-1
2|0|2|page-2
3|1|2|page-3
4|1|1|page-4
5|4|1|page-5

etc.

Now on the website I'd like to use this structure in the urls as well, creating friendly urls, that actually represent the structure of the website.

To clarify, I'd like the pages above to have urls like this:
1|0|1|page-1 -> mydomain.com/page-1
2|0|2|page-2 -> mydomain.com/page-2
3|1|2|page-3 -> mydomain.com/page-1/page-3
4|1|1|page-4 -> mydomain.com/page-1/page-4
5|4|1|page-5 -> mydomain.com/page-1/page-4/page5

I've configured the routes in a way that all the requests are fed to the same controller and method:

$route['(:any)'] = "website/view_page/$1";

Ok. So far I managed to get this concept working for a single level tree. I just look-up the variable fed to the view_page()-method in the database, to find out the correct page. But how to do this for a tree with two or more levels?

I think in some way I'd have to look up the complete tree structure, as I can imagine a situation as such:

mydomain.com/product1/details
mydomain.com/product2/details

Things I'm now thinking about is:

1) should I store the entire url path in the database (e.g. 'page-1/page-4/page5')

- this means that in my CMS I'd have to change all the urls of the children as well, once I change an items label

- how do get the entire part of the url as 1 variable?

2) if I keep the current structure .. do I start searching at the last url segment? Or should I start at the first one?


Well .. I've been talking to much for now .. would be happy to hear any comments or advice from you!

Thanks, Michiel




Theme © iAndrew 2016 - Forum software by © MyBB