[Catalyst] AJAX best practices, maximum availability

Renaud renaud at linuxaddicts.com
Mon Nov 20 20:46:34 GMT 2006


Hello,

I was wondering if the way I am trying to achieve things is the good way
or if that could be improved.
I guess I am not the only one trying to figure that out, so I hope that
can be helpful for other people thant me :)

This is what it's about:

I have a site where you can display information about restaurants. You get
those informations with links like /restaurant/1234/menu,
/restaurant/1234/access, /restaurant/1234/rates...

I'd like to update my page using ajax but without forgetting the clients
who cannot support it, so by default, the menu items link to
/restaurant/1234/menu, .../access, and so on.
If the client supports it, it replaces the links to functions that will
instead replace the content of some div where I display the requested
information. However to retrieve only the content of that div instead of
the whole page, it will fetch /restaurant/1234/menu/content,
/restaurant/1234/access/content, and so on...

On the catalyst side this is done with:

sub restaurant : Chained('') : CaptureArgs(1) : PathPart('restaurant') {
    # common things for a restaurant (/restaurant/1234)
}

sub access : Chained('restaurant') : CaptureArgs(0) : PathPart('access') {
    # Retrieve the access information (/restaurant/1234/access)
}

sub map_display : Chained('access') : Args(0) : PathPart('') {
    # Renders the whole page (/restaurant/1234/access)
}

sub map_content : Chained('access') : Args(0) : PathPart('content') {
    # Renders the "div" only (/restaurant/1234/access/content)
}


This means that for each kind of information I'd like to have for a
restaurant (access, rates, menu, ...), I have to write those 3 subs. Is
this a good way to proceed or am I abusing the Chained actions? I am not
sure this is the most efficient way to provide a page with maximum
availability.

Thanks for your comments, I hope I was clear enough.

Regards,
Renaud




More information about the Catalyst mailing list