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_root
should contain all files that need to be accessible for direct requests for someone contacting the server.
Therefore, media
, js
and css
should contain the media files (sounds, videos etc.), the JavaScript and CSS files your site needs.
index.php
is the entry script (front controller) to your application. This is where the request is examined and the correct controller and action gets loaded.
libraries
should contain the framework you are using plus additional libraries that you want to include (for example self-written ones).
I assume that var
is 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 application
directory should contain all the files that make up the specific application. That includes configuration and all your sub-modules, controllers, models and views...
The tests
directory could be used for unit-testing your controller and model classes (don't know why there is views
in there).
Hope this helps. It is a pretty commmon structure (although some names sometimes differ - e.g. var
could be data
etc.). 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...
Looks like a general site structure for the MVC pattern. There are tons of tutorials on this. There is enough of it even in here, check these MVC tagged questions.
Good luck!
精彩评论