How to organize a larger PHP project [closed]
-
12-12-2019 - |
Question
I'm trying to organize a larger PHP project with more than 50 files in code, not counting the resource files.
It looks like this:
- administrator files (php code and resource files)
- database framework
- resource files (images, templates, including PHP templates, CSS)
- CSS files
- scripts (Javascript and jQuery)
- PHP code (classes, controls)
- PHP and HTML scripts (acting as pages, placed in root)
How does one, properly organize a larger PHP project like this one?
Solution
First of all, a project that holds 50 files is not even called a project, in the real concept of the word.
Take a look at how the most used frameworks do that and you will get a place to start.
Some PHP frameworks:
So you can have a good reference, there is a simple good practice on PHP projects that tells that only the template, stylesheet and scripts files should be in a public directory, such as /var/www on your host. All the core application should be on a higher-level structure, for example:
src/ (The core application)
public/ (The public directory)
css/
img/
js/
index.php
You can, then, have a .htaccess file on the public directory as well, so you can control the requests.
But again, project architecture and structure organization goes a lot further than those simple tips.
OTHER TIPS
As it was already pointed out: you should separate the publicly available files ( css, images, flash, fonts and application entry points ) in one directory , and the rest of application - in another.
I think more important is the structure with the application itself.
- main framework, architectural class
- components and 3rd party libs
- custom code
- shared code
- application logic
- persistence
- templates
- admin module
- public module
- shared code
But this will depend on your personal preferences.