Is it a good idea to combine Ajax / UI JS Framework (ext, jquery-ui) with the MVC PHP framework (zend, symfony)?

I understand that this is a very general question, but I think that I'm really not looking for a definitive answer. As a newbie to PHP frameworks, I hardly hug him.

Javascript frameworks, especially with UI extensions, seem to have a kind of MVC-like approach, separating your JS code from your design. It just seems that it would be confusing to use the extra MVC structure on the backend.

Is this usually done for AJAX-driven applications? Is there an accepted / common way to do this?

+2
source share
5 answers

A quick example of how it can be combined for a Zend Framework application (and this is from a demo application that I wrote a few months ago):

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

After all, a PHP application knows that an AJAX response is needed for an AJAX request (less bandwidth, less processing, only a JSON or HTML fragment), but a regular request requires the entire generated page.

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

It is worth noting that context switching works well, making the request available in different formats - HTML / XML, CSV, etc.

+3
source

This is the next logical step from MVC, in my opinion. You already separate your access to data (model), from business logic (controller), from output (view) - now you just separate the behavior from the markup.

In my experience, it works great with AJAX functions, since you only need to change the view to return the necessary information in the form of JSON or XML.

+4
source

This is a very good idea, since PHP MVC structures are associated with JS frames :


updated link, thanks to "Exception e". A.

+2
source

Personally, we use Zend (MVC, as well as other aspects of the Zend framework) with jquery, and it works great together. Since not all of your interaction with the html page will be through jquery (ajax), then the standard MVC architecture is recommended. You definitely want the layers of your architecture (separation of model and presentation) and the presence of jquery (at least for me) and the additional β€œfeature” of the ability to execute your MVC asynchronously.

+1
source

It seems like it would be confusing to use the extra MVC infrastructure on the backend.

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

The connection is low, you only need to configure the tools for requesting data from your application server and do whatever you want on the client side. The line between these systems is simple and will not confuse you.
Extjs really has no mvc imho structure. It offers predefined rich ingredients. You glue these components together with some configuration and configure the URLs of your server from where the data can be extracted.

How do you get the zend mvc answer on ajax? I recommend that you watch the presentation on zf ↔ ajax from the zf project project.

+1
source

Source: https://habr.com/ru/post/886490/


All Articles