开发者

What folder structure do you use [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts,开发者_如何学运维 references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

Whether you structure your PHP application yourself or use a framework (MVC or other), what folder structure do you find most logical and you've been finding that you've been sticking to.

I still haven't developed a folder structure that I'm committed to, but I noticed that all my projects even the 2 page ones at least have a webroot folder (for files like htaccess, index, css, havascript) and another folder for the above the web root stuff where I try to keep as much of the files as possible. Pretty basic. Hoping to hear what others are doing to keep their programs organized.


My Default Folder Structure for web projects is

+projectname/
  +htdocs/
  | +assets/
  | | +js/
  | | +css/
  | | +img/
  | | +swf/
  | +content/
  +sys/
  | +temp/
  | +config/
  | +libs/
  +docs


If you use a framework, I would recommend sticking to the folder structure recommended for the framework. This means once you learn it, you can more easily adapt to other projects made using the said framework, and other coders familiar with the framework will understand yours easier as well.


For minor projects I usually use the following to work from:

  • httpdocs (web root)
    • data-providers (AJAX endpoints)
    • script (JS: utilities, scripts, libraries)
    • style (CSS and graphics - mainly sprites instead of the gfx folder I used to have)
  • models (PHP classes)

As for the PHP files in httpdocs I usually use one file per page / functionality (including basic CRUD operations).


I generally follow something similar to Martin Holzhauer, however I keep any common php includes in a separate tree (referenced via the include_path - call it common libs).

Each page intended to be addressable directly via the browser is created as index.php in its own directory. include files (or any additional content) specific to only that single page go in that directory, common includes go into the common libs.

By keeping the upload temp and include content outside the web root it simplifies security somewhat.

In practice I actually have several include paths - for a full explanation see article in PHP Architect earlier this year - but this allows me to control different setups (e.g. database settings) for dev / staging / live. And also to override particular files (e.g. to add additional logging / diagnostics)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜