Jump to content

Recommended Posts

Hello all,

 

I am just in the designing stages of a new site and I am curious about how to build the files.

 

I am using a lot of AJAX for different elements.  To check unique username, display data, and a host of others.  However, I don’t know if I should create a separate PHP file for each (uniqueName.php and Dispaly.php, etc).  Or should I create 1(ajax.php) and have a switch call to get the correct code. 

 

I am sure that both work fine, but I don’t want to problems down the road.  Please let me know your thoughts. 

 

Thanks,

 

Link to comment
https://forums.phpfreaks.com/topic/150490-file-sturture-ajax-and-php/
Share on other sites

I personally put a lot of effort into using as fewer files as possible for my site. I also use a bit of ajax, and I just have one "ajax.js" file for the actual ajax and a "misc.php" file for all ajax processing.

 

It makes your site a lot easier to update in the future if you have less files...

I'd utilize the MVC pattern and branch the view part into distinct parts that would deliver contextual content based on the request. The default would be to output HTML, but if the request is made using XHR then the output format would be XML or JSON. Considering that the views do not contain any business logic this would minimize duplicate code. The view would simply get the data and format it accordingly.

 

I'd strongly recommend against putting all your logic in a single file. While it may seem easier to manage because you've got less files, this won't really be the case. It's not really scalable nor portable. It's also easier to find things if they are split into multiple files in a logical and consistent directory structure.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.