Some background for my case:
Website's folder structure:
- assets (folder)
-- js (folder)
-- php (folder)
-- images (folder)
- index.php
- home.php
- other *.php pages
Web-page structure:
<?php include 'header.php';?>
<body>
<p>content</p>
</body>
<? include 'footer.php';?>
"header.php" includes "class.user.php", and latter includes "db_connect.php" (both files located in assets/php/). I have ajax calls from my-js.js (located in assets/js/), including to files in assets/php/ folder.
So, my specific questions are:
- Above page structure is not ideal (both header and footer either include a good bunch of "if-else", or an equally bood bunch of *.css and *.js that may be unnecessary for a particular page.
The structure like proposed here is ok, but having 2-3 files per actual page seems not necessarily for my case (all I got is 4-5 static pages with other 4-5 ajax-loaded pages). Overall, any advice on some good read/lecutres related to this topic (like udemy or just something good on the internet) are very welcome.
Each page starts with:
session_start (); require_once 'class.user.php'; $user = new USER();
Actually, even when I do ajax call from "my-js.js" to "ajax.php" to save data to db - I have to include those 3 lines in "ajax.php". So, is that necessary or can I make some sort of GLOBAL_PAGE_STARTER to shrink the code?
- Where is a good boundary between class.user.php and controller.php - say, logged-in user submits a form at home.php - is that a function to be handled by controller.php (which makes sense from mvc standpoint) or for class.user.php (which makes sense cuz this is the function of this class, logically speaking)?
Thank you for any comments, adequate criticism & advise!