[Catalyst] mapping application flow into a MVC framework (long)

Marcello m.romani at spinsoft.it
Mon Jul 11 18:24:14 CEST 2005


Lance Braswell ha scritto:
> Thanks to everyone who has given Catalyst to us. I'm
> pretty new to MVC frameworks as I suspect a lot of
> Catalyst users might be.
> 
> In my application I have what amounts to a tree of
> relationships that I would like users to be able to
> navigate.
> 
> Customers have Servers.
> Servers have Tasks.
> Tasks have HTMLForms.
> 
> User logs in and sees a list of customers. Clicks on a
> customer and sees a list of servers. Clicks on a
> server and sees a list of tasks, etc.
> 
> My MyApp::C controllers look like this:
> 
> MyApp::C::Customer
> MyApp::C::Server
> MyApp::C::Task
> 
> So everything relating to each class is in what I
> think is the right controller:
> 
> /customer/view/X -> show detail for customer X
> /customer/listservers/X -> show servers for customer X
> 
> /server/view/Y -> show detail for server Y
> /server/listtasks/Y -> show tasks for server Y
> 
> I can get all this going with Catalyst based on the
> fine examples out there but I'm stuck on the
> navigation. I want to be able to provide something
> like breadcrumbs at the top to navigate around the
> tree. But at each point of the user's location in the
> tree, the breadcrumbs have a different points of
> reference. For example using TT and CDBI, to get
> access to the current customer's name I need to have
> three different breadcrumb.tt templates with each one
> being relative to where I am in the tree. Namely to
> get to the customer name in the templates I would need
> to use variously customer.name, server.customer.name,
> and task.server.customer.name. I'm not sure if the is
> the correct way to handle it because it seems like I
> should be able to abstract the breadcrumbs out of the
> whole process and have a single  breadcrumbs template
> but then, presumably, the control logic of what to
> output is in the template itself. This doesn't seem
> right either.
> 
> All of the above has started to make me question
> whether my Controller classes are even right. Maybe
> they are too closely tied to the Model and I've
> misunderstood what controllers should be used for.
> 
> A more general observation is that a web app is a
> series of states. What gets output depends on what
> state you are in. Or, perhaps, pieces of the view of a
> web app are dependent on what context that piece of
> the view is in. For example I might want to view a
> list of servers in the context of belonging to a
> specific customer. Or I might to view a list of
> servers in the context of having searched for servers
> in a certain location. The common thing here is
> listing servers but which servers are listed depends
> on how I got there. I'm not sure how to handle this
> flow in a MVC way.
> 

I ran into similar problems too.
The (partial) solution I implemented is to keep track of a current set 
of selected items (in your app they are servers, tasks, etc.) and make 
the 'list' method of each specific model class to be aware of this.
In other words, /server/list would output the servers belonging to the 
currently selected customer if one exists, or the whole server list if 
no customer is selected.

The select/deselect methods are aware of the dependencies between objects:

customer->server->task

so if I'm browsing one task's forms and I decide to change customer, the 
current task is automatically de-selected, so that the application won't 
get into an inconsistent state (that is, the currently selected task and 
server do not relate to each other).

This kind of logic is very simialr to what you find in public 
directories, where you have categories and subcategories.
A "navbar" for your application could look like:

Customers > "customerName" > Servers > "serverName" > Tasks > "taskId"

For example, clicking on "Servers" would bring you to the server list 
page for "customerName" (and deselect current server and task), while 
clicking on "serverName" you would see that server's detail page.

The state (i.e. the current selection) is obviously kept inside the 
session "object" (whatever this means in a particular implementation).

> Sorry for this long and rambling posting. I was just
> hoping that someone out there might be able to point
> me in the direction of mapping web application flow
> into a MVC framework.
> 

As you can see from my quite long answer, I can't give you an answer. I 
hope my 0.02 cents bring something useful to the discussion, though.

> regards,
> Lance Braswell
> 
> 
> 		
> ____________________________________________________
> Sell on Yahoo! Auctions – no fees. Bid on great items.  
> http://auctions.yahoo.com/
> 
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
> 

Thanks for bringin the subject to the list. I think it's a potentially 
very broad subject, and one everybody has faced, with or without using 
catalyst, while developing non-trivial web apps.

Marcello



More information about the Catalyst mailing list