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!

Thanks,

Dom

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to