airportmarc Posted March 21, 2009 Share Posted March 21, 2009 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, Quote Link to comment https://forums.phpfreaks.com/topic/150490-file-sturture-ajax-and-php/ Share on other sites More sharing options...
jackpf Posted March 21, 2009 Share Posted March 21, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/150490-file-sturture-ajax-and-php/#findComment-790441 Share on other sites More sharing options...
Daniel0 Posted March 21, 2009 Share Posted March 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/150490-file-sturture-ajax-and-php/#findComment-790535 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.