[Nitro] Modelling controllers strategies

Alan Garrison alang at cronosys.com
Mon Aug 22 14:13:01 EDT 2005


Hi, in my rare pockets of spare time I've been experimenting with a 
designing
a small CRM application using Nitro.  (See www.SugarCRM.com for what I'm
modelling the UI after, and if you are in a puking mood, download their 
open
source zip and take a peek).  I started by looking at Spark and got just
some very basic stuff running so far.  What I've run into is some confusion
on how the controller class should behave for what I'm trying to do.  Spark
is simple in that it (basically) deals with just one Og object (WikiPage). 
What I'm trying to do deals with (potentially) numerous business logic
objects (Contacts, Accounts, Projects, Leads, etc).  I've got basic Og
objects for these, and that in itself isn't a problem.

For example, I envision talking to the controller like so:

 /view/Home -- Display homepage (index default page)
 /view/Contacts -- View Browse/Search/Panel for Contacts
 /view/Accounts -- View Browse/Search/Panel for Accounts
   (Or perhaps have a "/search/Contacts", use different controller call)
 /view/Contacts/239030294083820 -- View this contact's details
 /edit/Contacts/239030294083820 -- Edit this contact's details

All "screens" will have some common header and footer templating logic,
but the main guts of the page will behave based on which object type
you are loading/editing.  So my initial question is "should I try to
have one controller try to handle everything?"  Like so:

-----8<-----
class MyController < Nitro::Controller
  def view(screen = 'Home', oid = '')
    @someobj = MyBaseClass.find_by_oid(oid)
    ### now try to determine what to do based on the screen
    if screen == 'Contacts'      # do something...
    elsif screen == 'Accounts'   # do something...
  end
  ### and so on...
end
-----8<-----

Or would I be better off having a controller per object type (even though
I'm not quite sure how to handle the common header/footer stuff)?

-----8<-----
class ContactsController < Nitro::Controller
  def view(oid = '')
    # We know it's a contact already
    @somecontact = Contact.find_by_oid(oid)
  end
  ### and so on...
end

### probably in a separate file:
class AccountsController < Nitro::Controller
  def view(oid = '')
    # We know it's an account already
    @someaccount = Account.find_by_oid(oid)
  end
  ### and so on...
end
-----8<-----

Years of mod_php style programming is making my grokking of the MVC
paradigm a little bit challenging.  :)  Any suggestions to the above, or 
maybe
there's a better way that I'm missing?


-- 
Alan Garrison
Cronosys, LLC <http://www.cronosys.com>
Phone: 216-221-4600 ext 308





More information about the Nitro-general mailing list