views:

182

answers:

2

Hi!

I am writing application in PHP (+ MySQL database), but it gonna be mainly AJAX aplication. So, I am wondering, how to create frontend? Frontend also in MVC? Is it possible?

+3  A: 

Of course MVC is possible on the front end also. JavaScript is a rich programming language, and since MVC is only a design architecture it's language agnostic. There are some attempts at MVC in some JS frameworks, mainly sproutcore and JavaScriptMVC.

I guess there are two paths to go, either separate PHP and frontend completely, and just pass JSON or XML with ajax between them, or blend them like a classic web application, and do some ajax-requests on top of that.

finpingvin
+1  A: 

Unfortunately it is still not a good idea to rely on JavaScript being enabled, so having JavaScript applications "fail" gracefully is preferred.

I would recommend creating a basic PHP/HTML click-and-reload application first, which would allow dinosaurs to use the basic features of the site, and then build a JavaScript/AJAX application on top of that, which would enhance the base application.

As to the MVC question: It is definitively possible to create a JavaScript MVC front-end. I tried it myself a few months ago and it worked great. Just keep a close eye on the scope of your function calls. They can get away from you if you aren't careful :-P

Atli
For many applications, demanding users enable javascript is completly acceptable. E.g. How would google Docs spreadsheets work if JS was disabled?
rjmunro
@rjmunro Google Docs is an exception, in that it was created to replace a functionality usually reserved for desktop apps, and can not reasonably be reproduced in HTML alone. It hardly compares to 99% of web sites. -- But I would agree, that it is "acceptable" to require it, but still not "preferred". Many mobile phones, for example, have a hard time with JS built for desktop browsers. -- Bottom line, if you want to reach the largest audience, gracefully falling back to the most common denominator (pure HTML, for the web) is "ideal", and I will (still) always recommend that.
Atli