2 Replies - 12481 Views - Last Post: 23 June 2011 - 12:43 PM Rate Topic: -----

#1 Dannyboy997  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 64
  • View blog
  • Posts: 258
  • Joined: 17-April 09

Ajaxed MVC Framework

Posted 21 June 2011 - 09:41 PM

Been a while that i've been on here, but it seems as this topic isn't out there on the interwebs or my wording on the subject is wrong. Either case i've come here for suggestions.


So basically I have written a php framework that applies the MVC design architecture. I tried all sorts of different design patterns, and well mvc suites my needs very well. I did not want a huge bloated one such as the big chiefs in town. So I created my own that had only my requirements and features that I needed.

Now the framework is built, and works perfectly. But heres my question:


How would I go about adding an ajax layer to the framework?


Meaning that every time you would click a link or change pages it would use ajax to complete your request while still being within the framework. Now I could create several different php files that I would go and fetch for the data needed to update the site, but having lot's of loosely written php code everywhere is not suitable. That's one of the reasons I went with mvc in the first place. I haven't thought of many ways of accomplishing this.


Though some articles / forums online were talking about ajax inside the php framework, such as Zend and Codeigniter (If i'm correct), but it wasn't a framework built on top of ajax. Also I would be using jquery to achieve the ajaxing if that's much help.

Not sure if I explained it well, makes sense in my head as usual but writting it becomes another outcome.


Thanks,
Daniel

Is This A Good Question/Topic? 0
  • +

Replies To: Ajaxed MVC Framework

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4364
  • View blog
  • Posts: 12,182
  • Joined: 18-April 07

Re: Ajaxed MVC Framework

Posted 21 June 2011 - 11:16 PM

Well lets get one thing straight here... AJAX is Javascript which is client-side. This means in MVC it is part of the View. It is for presentation. So your view classes are the ones that are going to be generating the AJAX presented to the user. They of course will interact with your controllers just like your Views would. Whether the request is coming from your HTML page in the form of a HTTP request or through an AJAX request, the controller shouldn't care. As far as it knows, it is a request like any other. The controller would then interact with the model as it always does and return the response not to the client in the form of an HTML page, but in the form of a response to the AJAX call (This response may still be full HTML source or could be XML or JSON).

If you designed it correctly, your controllers should be independent of your views and be designed to simple take requests and return output. Your AJAX will just be the facilitator and not your web page being loaded into the browser.

Lets say you have a page that lists some records. Your visitor requests records 1 - 10 which they hit a button and it calls up your controller which validates the business logic and communicates to your model for info. It then gets the records and returns it back to the view by reloading the page and the view formatting the 1-10 records. Now with AJAX it is going to call the same controller asking for records 20-30 and the controller talks to the models and returns it back to the AJAX CODE in which case it then formats it and updates the controls on the page.

Hope that helps explain things. :)

This post has been edited by Martyr2: 21 June 2011 - 11:18 PM

Was This Post Helpful? 2
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3040
  • View blog
  • Posts: 10,620
  • Joined: 08-August 08

Re: Ajaxed MVC Framework

Posted 23 June 2011 - 12:43 PM

View PostMartyr2, on 22 June 2011 - 02:16 AM, said:

AJAX is Javascript which is client-side.

To be more precise and to avoid confusing people who are trying to learn it, AJAX is the communication techniques used between Javascript and in this case PHP. Although it generally starts with Javascript, It isn't any one language so it can work with whatever style of programming you use on the server side scripting.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1