-- Cameron <themsel...@gmail.com> wrote
(on Tuesday, 22 September 2009, 12:10 PM +0800):
> Hi everyone, I just wanted to see if anyone else had had a good long
> think about this sort of thing before I decided one way or the other.
> 
> Basically I have been playing with the context switch action helper,
> and it has opened a whole new world of possibilities in terms of
> application structure, but i'm not certain if i'm about to head down a
> path of over-engineering or not.
> 
> As an example, my controllers have an autocomplete action. It
> essentially switches off the layout and returns the appropriate data
> in JSON format - all of which is fine and dandy, and there's a bit of
> processing in the whole thing so it's not unreasonable that it's its
> own action, HOWEVER... stopping and thinking for a bit, retrieving a
> list of autocomplete options IS just a "list", and hence shouldn't it
> be a function of the /list action? with the format simply decided by
> the context switcher? it seems to make sense to me, but then i start
> to think about how many other actions this might mean reworking -
> where do you draw the line? i guess you could make your entire
> application a context switch of /, which is obviously taking it too
> far, but you see the point...

I've been playing with similar things recently, and found that one way
to both simplify these sorts of situations as well as standardize them
is to start thinking of my application in terms of ReSTful resources.

For instance, I implemented a RESTful controller, which gives me your
standard BREAD or CRUD actions (browse-read-edit-add-delete /
create-read-update-delete). When you map ContextSwitch on top of it, you
can also add some plugins for checking for specific Content-Type headers
-- which allows you to do things like detect if JSON or XML is being
requested. This then allows me to simply create different view scripts
for each context I have. What this ended up meaning was that I could use
my "list" action ("index" in the Zend_Rest_Controller) to serve both a
list of resources as well as JSON for use with an autocomplete.

The beauty is that the basic application and controller logic remains
the same -- it's simply the view logic that differs, based on the
content-type of the request.

> I'm just thinking out loud, I'm guessing the answer is that there's no
> "perfect" structure, and it's better to just write the code and get it
> working rather than philosophize endlessly over the best possible
> solution, i just thought this one might be an interesting debate for
> the mailing list.

Agreed -- there is no "silver bullet". But I think you're on the right
track: you're asking the important question of "can I re-use what I've
already done?"

-- 
Matthew Weier O'Phinney
Project Lead            | matt...@zend.com
Zend Framework          | http://framework.zend.com/

Reply via email to