Sunday, November 30, 2008

MVC falling to pieces for modern AJAX apps

Hey guys

I've been developing web applications with Cake for almost 2 years
and I never want go back to the old vile php ways again.

I must say that with more advanced applications the MVC concept isn't
working so good any more. With any halfway decent webapp you will have
a lot of controller logic in the views, namely all those JavaScript
functions you use.

For example: Passing form field values to the server via ajax calls
for validation or opening modal windows over content items (ie context
menus etc)

If you take JavaScript even a step further then you'll end up with
frameworks like ExtJS ... you don't write a single line of HTML code
anymore, just the body. The framework then will insert all the lists,
menus or whatever you want onto the canvas and populate them with data
it gets from the server via json.

Working with Cake this gets really ugly .. because then you will end
up with redundant code, data validation on the server side but also on
the client.

Yesterday I read an article on this issue (http://advogato.org/article/
993.html
) ... it's a bit strong anti-PHP but it hits the spot. It goes
on about combining a MVC framework (Web2Py) with a Python-to-
Javascript compiler (Pyjamas) which in the end will result in coding
in Python and having a framework do all the html work .. so like Ext
but with a proper server-side backend.

What also would solve the problem of code redundancy is a JS framework
like TrimPath (http://code.google.com/p/trimpath/wiki/TrimJunction)
where you only code in JS and the same code gets executed on the
server and the client ... BUT ... do we really want to code ours apps
in JavaScript? I for sure don't want to.

So I had this idea yesterday how to solve this problem at least
partly .. by partly I mean at least all the data validation.

Develop a doped up form helper. Said form helper gets the validation
rules for every field from the model and implements the JavaScript
rules automatically ... on the server side everything stays the same.

For examle if field "name" has the NOT_EMPTY validation rule, the
DopeFormHelper could add this validation to the view so even before
submitting to the server the user gets notified of his mistake.

What I'm not quite sure of is ... am I breaking all the MVC rules
thinking like this? AFAIK the view (and therefore the Helper as well)
should have no knowledge of any model rules or code. How do I get
these informations in there?

So what do the gurus think of this? Any ideas how to keep all that JS
code out of our views?

Enjoy your weekends

wirtsi
--~--~---------~--~----~------------~-------~--~----~
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: