views:

298

answers:

5

i'm developing a web application that focus heavily on ajax. the whole application is just on one page except for the threads that are in traditional pages so they can be indexed.

so i have to have very structured JS-codes and i wonder if they are any frameworks out there that are for ajax-based applications.

eg. codeigniter, cakephp and others i have read about dont focus on this. they just organize regular php code according to mvc.

cause my code starts to be very messy (especially the js code) and i really need some structure here. is there a way to have same mvc + oop structure in javascript? i never heard anyone talking about it. even if i put js codes in separate files, one for each page for example, there are a lot of lines and i feel lost and crunch whenever i have to add some new functionalities.

would be great with suggestions and ideas how to structure this up!

+1  A: 

You might check out Zephyr. Never used it myself, I just know that it's mainly for AJAX apps.

Mike Crittenden
interesting concept, but unfortunately not a lot of followers and it uses cpaint and its development stopped 2007.
weng
+1  A: 

I think you have the wrong mindset about this.

AJAX-heavy sites or applications aren't that much different form their Web 1.0 counterparts in their underpinnings. You still have the same basic components: HTTP Requests and responses. It's just that with AJAX you rarely request a full HTML page. Most of the time you're requesting snippets of HTML, XML, or JSON.

So, just because you'll have a web site/app that is 90%+ AJAX driven doesn't mean you need to throw away existing conventions like MVC and look for something new.

And most modern frameworks have plenty of AJAX stuff baked in: ZF, symfony, cake, etc.

EDIT

I don't know of any framework, PHP or JavaScript, geared towards what you are asking. That being said, you might get something out of watching High-performance JavaScript: Why Everything You've Been Taught Is Wrong, Designing the Rich Web Experience, and High Performance Ajax Applications, even though they're a couple years old now.

Also, consider digging into projects that are AJAX heavy and seeing how they tick. ExtJS and jQuery UI based applications would be a good start.

Peter Bailey
i understand that, i didnt say that i wanted to throw away mvc pattern for backend, i wondered how i could organize the javascript/jquery code in the front end, cause my application got a lot of that code. so i need a php ajax framework for that. and i found a list of php ajax frameworks on the net. ZF is for Java?
weng
I see. I'll edit my answer to provide some info
Peter Bailey
A: 

Check out Yii or Zend Framework.

Eric Butera
could you briefly explain how those can help me with the communication between javascript and php or the structure of the javascript code?
weng
If you follow the framework guidelines on how to do things then it will just work. A json response is the exact same as a normal text/html response only you get json instead of html. So you're looking for the benefits of a normal framework that eases the pains of parsing request data and dishing out proper responses. If I have a ZF app I can still use my core codebase to talk to a client over xml or json. Those are just transports. But the framework helps guide you on how to create/organize it, which is what you were after in the first place.
Eric Butera
+1  A: 

The symfony framework is great for Ajax, and they have a well-thought-out approach involving the MVC backend and your JavaScript code, especially the popular JavaScript libraries like JQuery and Scriptaculous.

It would be worth your time to read the chapter on Ajax in the Symfony Askeet tutorial just to see how someone else has done it. Also, the Ajax chapter in the older symfony book outlines other uses besides the search autocomplete feature shown in the Askeet tutorial.

Nathan
A: 

I build apps like these. My architecture:

  • Server-side: Zend Framework
    The PHP code is exposed as a set of JSON-RPC web services. The web services are implemented with Zend_Json_Server, and don't do anything HTML generation (all UI is handled client-side). Because of this, the server-side code is fairly limited (database interaction, session management, and security).
  • Client-side: ExtJS
    The code is bootstrapped from a single PHP page hosting the ExtJS framework, and after that dynamically loads javascript components as separate files on-demand. Each javascript component calls a web service to initialize itself and load/save data. There are also special translation files (dynamically generated from PHP) to patch the class prototypes with translations.

In this approach the web services do not send back any sort of pre-generated HTML. They are data bridges, shuttling records back and forth. All UI construction is done client-side. Zend_Json_Server exposes a PHP class as a service (the methods of the class are the functions of the service). This keeps the PHP design clean, and offers ultimate flexibility in UI. The mobile front-end is built around the same classes as the RIA front-end. It's also easy to build other apps on top of the same web services (e.g. a windows app, an iphone app, ...). The minimal amount of PHP code keeps server overhead low.

If I were you I would focus more on what javascript framework you're using than on a PHP framework. If you're going whole-hog ajax (without basic html fallback), there's simply no point in getting the server involved in generating the UI (it just slows the app down).

Joeri Sebrechts