I’ve been reading about site structure in PHP, but whenever I read or ask questions about site structure, I get something like this
/application
/config
application.ini
/controllers
/views
/models
bootstrap.php
/var
/log
/tests
/controllers
/views
/models
/libraries
/mylib
/myframework
/web_root
/media
/js
/css
index.php
.htaccess
Now this is a good answer, but I still dont fully comprehend. It would help a lot more if I could get some examples of good site structures with actual files in place (and what they do), or at least with explanations on what each folder is meant to hold explicitly.
Thank you
This obviously assumes you are using some kind of framework…
web_rootshould contain all files that need to be accessible for direct requests for someone contacting the server.Therefore,
media,jsandcssshould contain the media files (sounds, videos etc.), the JavaScript and CSS files your site needs.index.phpis the entry script (front controller) to your application. This is where the request is examined and the correct controller and action gets loaded.librariesshould contain the framework you are using plus additional libraries that you want to include (for example self-written ones).I assume that
varis supposed to hold the files where data of your application is stored (for example when using SQLite or text-based data storage).logs– well, you probably figured that one out…The
applicationdirectory should contain all the files that make up the specific application. That includes configuration and all your sub-modules, controllers, models and views…The
testsdirectory could be used for unit-testing your controller and model classes (don’t know why there isviewsin there).Hope this helps. It is a pretty commmon structure (although some names sometimes differ – e.g.
varcould bedataetc.). But I would still recommend you to experiment so that you can find the application structure that suits you best. You should still take care of only having files being accessible directly if they should be and separating stuff like your application (plus having models, controllers and views separately), data files, temporary files and libraries…