Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Best practice in how to organize ajax server-side pages

Posted on 2012-04-01
4
Medium Priority
?
318 Views
Last Modified: 2012-06-03
I am using an old phpbb framework for a website.  We've only just 'discovered' AJAX and are intending using it to update the site a bit.

With phpbb the basic file structure for each page of output is like this (eg: xyz.php)
1) main php files are in the root: \\xyz.php
2) functions are all in included files: \\include\function_xyz.php
3) template files are located: \\templates\myTheme\template_xyz.tpl

Is there a best practice (or even your own prejudice?) on where I should be putting functions/pages that I am calling from AJAX (eg: from the xyz.php HTML page)?

eg:
1) create a folder \\ajax\ajax_xyz.php, and call this from the UI
2) put the function which returns data to the ui in \\include\function_xyz.php, called from \\xyz.php, which in turn is called from the UI
3) etc etc...
0
Comment
Question by:PaultheBroker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37793341
I think I would go with #1.  My instincts tell me that will give you better organization.  But leave the question open for a day or so - there will be other opinions and suggestions from other experts.
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37793543
I'm with Ray on this.
I'd go with #1.
0
 
LVL 30

Accepted Solution

by:
Olaf Doschke earned 2000 total points
ID: 37793960
Are you talking about what php script you would requestvia javascript xmlhttprequests? Requests you make would depend on the functionality you need and the data you want to retrieve. That would seldom be one php script per php page, but one per topic, functionality, etc.

Eg a cascaded choice of a users city could be done by:
1. Initially giving the choice for a continent.
2. After the user selects a continent, calling getcountries.php, returning a list of countries of the choosen continent.
3. After the user selects a country, calling getcities.php, returning a list of the cities of a choosen country.

That's already a case of calling back into two different php scripts.

These two methods could of course be part of one \\ajax\ajax_xyz.php analog to \\include\function_xyz.php, but why would things you request from UI not also be \\include\function_xyz.php and if you think OOP and make use of MVC design pattern, this could also be done for ajax, all ajax calls could go into one ajax controller, which redirects and reuses view and model components to generate html snippets or return some data in the form of json or xml instead of a php array.

Bye, Olaf.
0
 
LVL 6

Author Comment

by:PaultheBroker
ID: 37794197
I like the per topic suggestion - its is how the includes are organized (mostly!)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question