views:

280

answers:

6

I realize this is a very generic question, but I guess I'm not really looking for a definitive answer. Being new to PHP frameworks I'm having a hard time getting my head around it.

Javascript frameworks, especially with UI extensions, seem to have their sort-of MVC-like approach by separating your JS code from your design. It just seems like it would get confusing to use an additional MVC framework on the backend.

Is this commonly done for primarily AJAX-driven applications? Is there an accepted/common way of doing it?

+1  A: 

Personally we are using Zend (MVC as well as other aspects of the Zend framework) with jquery and it works very well together. Since not all of your interaction from the html page will be via jquery (ajax) then a standard MVC architecture is highly recommended. You certainly want the layers of your architecture (separating the model and the view) and having jquery is (at least to me) and additional "feature" of being able to execute your MVC asynchronously.

Arthur Frankel
I'm sort of window-shopping for projects (hopefully) further down the road, but the app I'm working on right now is almost fully ajax-driven, powered by jQuery + UI. I have no PHP framework -- just JS functions that, for example, ajax-load a certain script that fetches a page according to its given parameters. Everything is pretty simple, but it would be nice not have big blocks of PHP in the middle of HTML pages and vice-versa.
Greg
+2  A: 

It's the next logical step from MVC, in my opinion. You already separate your data access (model), from the business logic (controller), from the output (view) - now you're just separating behaviour from markup.

In my experience, it works really well with AJAX features, since you only need to change your View to return the necessary information as JSON or XML.

nickf
I guess I'm coming up on this topic a bit ass-backwards. I'm familiar with jQuery pretty extensively, but I've never really dealt with MVC.
Greg
+1  A: 

It just seems like it would get confusing to use an additional MVC framework on the backend.

No need to worry about that. You can use zend framework and extjs for example independently while developing, they are really separate products. The dependencies between these layers should be kept simple. No need to worry.

The coupling is low, you only need to set up means to query data from your server-app and do whatever you want with in on the client side. The line between these systems is simple and won't confuse you.
Extjs doesn't really has an mvc structure imho. It offers predefined rich components. You glue these components with some configuration and set up the urls of your server where data can be fetched from.

How do you get your zend mvc respond to ajax? I recommend you to view the presentation about zf ↔ ajax from the zf's project lead.

Exception e
+2  A: 

A quick example of how it can fit together for a Zend Framework app (and this is from a demo app I wrote a few months ago):

  • Use the MCV Framework to build a fully functional site (which works without javascript).
  • Modify the controller to understand the difference between a 'normal' request and an AJAX request (Zend's context switching makes this easy).
  • Add Javascript (in my example jQuery) to cleanly replace the links with AJAX events.

In the end, the PHP app knows that an AJAX request needs an AJAX response (less bandwidth, less processing, only JSON or HTML 'snippet'), but a normal request needs an entire page generated.

Basically, you're just using AJAX to request (or update, or add data to) the 'view' template, without having to process the entire layout. The Zend Framework Context Switch Action Helper may help this make more sense.

It's worth mentioning that context switching works well in making a request available in different formats - HTML/XML,CSV,etc.

Tim Lytle
It's starting to make sense, thank you.
Greg
Glad to hear it - if you want to contact me off SO I can send you some source code that may help.
Tim Lytle
+1  A: 

Its a very good idea, since the PHP MVC frameworks are bundled with JS frameworks:


updated link, thanks "Exception e".

powtac
Is there a framework in particular that would be a "best" for Ext (or jquery + controller + ext) or is that kindof an asinine question?
Greg
There are quite a few people at extjs that use ZF. Any framework should do, zf does. The correct link to symonfy ajax is http://www.symfony-project.org/book/1_2/11-Ajax-Integration. You wont use the examples shown there, because ext is most suited for building a complete app without html. The examples shown there mix html and javscript. Jquery and prototype are libraries, not a systems of desktop components like ext.
Exception e
A: 

@Tim Lytle

Is this demo app available somewhere? I'm going to develop a "gmail-like" (fragment navigation) web app with dojo and zend and I am interested in your mvc-ajax solution.

Thanks

gergely