Hi AD,

Thanks for the speedy response, much appreciated!

I totally agree with the point about database driven, caching the
routes is definitely the way to go and seems fairly simple to
implement (I think!).

I also agree with keeping the routes simple, and I'd love to, maybe
I'll have to go to the regular method of /category/1/chocolate etc.
for example...

I think the only reason I was looking at the more complex options was
to have the ability to store the current ID of the row, to enable
simple breadcrumbing and navigation generation.

Perhaps I should just keep the two separate for the time being...?

Thanks again for your help!

Dom

PS.

Just out of interest, a site with the navigation style closest to what
I'm after is:
http://www.nhm.ac.uk/


On Mar 18, 11:18 am, AD7six <[email protected]> wrote:
> On Mar 18, 11:53 am, dom111 <[email protected]> wrote:
>
>
>
>
>
> > Hi All,
>
> > I'm relatively new to Cake as a framework, but compared to the others
> > I've looked at, it ticks the boxes that I've been looking for, so
> > thanks for all the hard work the team has put in!
>
> > I've got a pretty specific issue, and one I'm not finding a lot of
> > information on (maybe I'm not looking in the right places, I hope I
> > haven't missed a discussion in here...), and I'm hoping it's not
> > because it's too hard to do...
>
> > It's regarding routes, and as the subject suggests, dynamic database-
> > driven ones...
>
> > I'm currently working on a site that can handle a dynamic admin-
> > managed hierarchy, with customisable URLs and the ability to link the
> > same information in many places, building the correct breadcrumbs/
> > navigation. Maybe I'm the only person crazy enough to think of it, but
> > I'd like to think not...
>
> > What I'd like to do is match the following URLs (for example):
>
> > / => pages->index()
>
> > // shop data
> > /shop => shop->index()
> > /shop/food => shop->section('food') or sections->view('food')
> > /shop/food/banana => shop->product('banana') or products->view
> > ('banana')
> > /shop/food/chocolate => shop->section('chocolate') or sections->view
> > ('chocolate')
> > /shop/food/chocolate/mars-bar => shop->product('mars-bar') or products-
>
> > >view('mars-bar')
>
> > // static pages
> > /pages/about => pages->view('about')
> > /pages/about/opening-times => pages->view('opening-times')
>
> > // 'modules' eg. more processing to manage than a static page: contact
> > validation/emailing/database
> > /pages/about/donate => modules->load('donate')
> > /pages/about/contact-us => modules->load('contact-us')
>
> > Also, it'd be nice (but to avoid making things even more complicated,
> > not essential) to have /shop/food/choclate/search.html or filter.html
> > to redirect to the shop->
>
> > I know I could easily hard-code all the hierarchy, but I need to give
> > the ability to re-arrange the sections to the site administrator.
>
> > The attempts I've had so far, have yielded less than successful
> > results...
>
> > I created a Route model in which the structure was:
>
> > id int(11) auto_increment
> > pattern varchar(255)
> > controller varchar(255)
> > action varchar(255)
> > permalink varchar(255)
> > left int(11)
> > right int(11)
> > parent_id int(11)
>
> > The pattern field contained the route string as used by Cake eg:
>
> > pattern '/'
> > controller 'pages'
> > action 'index'
> > permalink ''
>
> > or
>
> > pattern '/shop/food/chocolate'
> > controller 'sections'
> > action 'view'
> > permalink 'chocolate'
>
> > or
>
> > pattern '/shop/food/chocolate/:permalink'
> > controller 'products'
> > action 'view'
> > permalink NULL (which would use the :permalink in the URL I believe)
>
> > I'm thinking that this would work if I added a flag indicating if the
> > row was related to a shop section so that extra processing could be
> > done in the routes.php file to add /section-name/:permalink to
> > redirect to product->view(). The routes.php file I managed like so:
>
> >   foreach (ClassRegistry::init('Routes')->find('all', array('order' =>
> > 'LENGTH(`pattern`) DESC')) as $data) {
> >     extract($data['Routes']);
>
> >     // set up the route
> >     Router::connect(
> >       $pattern,
> >       array(
> >         'controller' => $controller,
> >         'action' => $action,
> >         'permalink' => $permalink
> >       ),
> >       array(
> >         'pass' => array(
> >           'permalink'
> >         )
> >       )
> >     );
>
> > but it feels a bit too 'hacky' and I'd like to check first that
> > there's no other way to address the issue.
>
> > Another way I've thought to try is to create a routing 'controller'
> > that parses the url but if I were to redirect all requests to that
> > controller, would it be easy enough, or even good practice, to call
> > another controller and it's action from within the main routing class.
> > It all feels wrong!
>
> > I wouldn't mind rewriting the router also, which is another thought I
> > had, but again, is there a correct protocol to follow before undoing
> > all the good work done thus far?
>
> > If anyone has any suggestions, resources or even encouragement, it
> > would all be very much appreciated!
>
> > Apologies if I've missed an existing discussion or if my rambling is
> > too incomprehensible!
>
> Wanting to be able to create (as an admin user) a specific url for
> some content seems 'normal' but wanting to make the entire routing
> system work that way is likely to make things way too slow.
>
> For one off pages, you'd just call Router::connect for them before
> your other routes (probably via aftersave -> save routes to a file,
> begining of routes.php check for your admin-created routes file).
>
> For the general case why not consider something like:
> Router::connect('/pages/*', array('controller' => 'pages', 'action' =>
> 'display'));
> (
> Router::connect('/products/:id/*', array('controller' => 'products',
> 'action' => 'view')); // append whatever slug/seo fluff you like
> OR
> Router::connect('/p/*', array('controller' => 'products', 'action' =>
> 'view')); // append whatever slug/seo fluff you like - last one being
> the product slug
> )
> (
> Router::connect('/category/:id/*', array('controller' => 'category',
> 'action' => 'view')); // append whatever slug/seo fluff you like
> OR
> Router::connect('/c/*', array('controller' => 'category', 'action' =>
> 'view')); // append whatever slug/seo fluff you like - last one being
> the category slug
> )
>
> IMO the key to mastering/having simple routes is to always have
> something fixed ('e.g. /p/') in the route to make matches easy find/
> debug/etc. . Making Routes themselves db dependent is a recipe for
> slowness and general disaster ( what happens if the db goes
> offline? ).
>
> hth,
>
> AD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to