Sunday, August 29, 2010

Re: Dynamic menu based on deep relationships

I think I know what you want but I'm not sure... let me know if I'm
close.

I'd do it one of two ways

1) User selects a province, page refreshes and now there are two
dropdown boxes, first one has province selected, in the second user
chooses region(and so forth)
2) User selects a province, select box appears with regions in that
province(and so on and so forth)

For method 1 I'd have the javascript submit the page each time a
dropdown is changed- then the controller can figure out which menu
items to load for the next select box. If several select boxes have
been chosen, such as province, region and suburb, and province is
changed, then the form would basically reset to only show the province
and region select boxes.

For method 2 I'd either use ajax to query the database based on the
change in any of the select boxes, and reload the values in the select
boxes. When the last select is chosen it loads the proper view.

As for the menu knowing where the user is, simply set the relevant
fields(province_id, region_id, suburb_id and establishment_id) based
on the data that is loaded... if you load a suburb it should be
relatively easy to get the region_id and province_id for that suburb.

On Aug 29, 10:59 am, Bryan Paddock <bryanpadd...@gmail.com> wrote:
> Hey all,
>
> I've looked through pretty much every menu tutorial out there for cakephp
> and have sat for ages to try and think up how I can achieve this but to no
> avail.
>
> I have a semi-complex database structure of establishments (restaurants,
> hotels etc).
>
> Province -> Region -> Suburb -> Establishment
>
> as well as
>
> Category -> Subcategory -> Establishment
>
> Now the user needs to be able to select the province from the list, have it
> show the regions under that province, then the suburbs, then a list of
> subcategories under that province that contain establishments. I can handle
> the fetching the data (eg how to pull out the list using containable etc)
> but it's the starting foundation I'm having problems figuring out. IT will
> be done in ajax but the actual ajax part I could probably do myself.
>
> I would like to have the menu also build itself from the page that the user
> is on (eg the user can browse around the menu in itself but if he also goes
> to the a related page (eg suburbs/view/cape-town) then the menu should know
> where the user is)
>
> I honestly can't think of even where I should start here. Building a menu is
> simple in plain php with simple relationships but it's getting pretty tricky
> with all the extra levels.
>
> Does anyone have any advice on a starting point which I could work with...
> I'm trying to make it extendable in the sense that I don't want to hard code
> anything.
>
> I'm starting to think it may be better off to handle the menu separately in
> a menu model and update the menu on each of the related models afterSave(),
> etc callback but that seems a bit unnecessary as it would just be duplicated
> data.
>
> Thanks in advance!
>
> Bryan

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: