Last post Jan 25, 2011 01:42 PM by geek.rutherford
Jan 14, 2011 03:28 PM|jnesbitt|LINK
In the cms I'm designing, all of my pages are represented by page objects which exist in a hierarchal structure that mirrors their logical layout in the website. At first glance, this seems like a simple tree data structure and accessing a particular page
would be a simple matter of looking up a node by it's id. I also need to be able to traverse up the tree in order to do things like generate a bread crumb in the view. The complexity arises with the requirement that a particular page can live in multiple
locations. Now, nodes can have multiple parents, making the generation of a breadcrumb impossible without knowing which parent node to traverse up into. This means that I need to map an incoming request not to a particular page object but rather a path to
that page object. I could do this if the request contained a list of ids making up a path but that would result in complex urls and that might make generating links harder.
Since a path is simply a list of nodes, I could create a Path class, identified by a single unique id, containing a list of Node objects (concrete node classes are Page and Directory), with the last item in the list being the leaf Node (destination Page).
What I don't like about this idea is that I have to keep these lists in sync with the site's natural tree structure. This creates the possibility that they could get out of sync and that's a code smell for me.
Is there a more elegant way to do this? How have you handled this problem in your own CMS design?
Jan 25, 2011 01:42 PM|geek.rutherford|LINK