Ask HN: PHP Directory structure and code organization
I work for a company (PHP shop) where we are looking at cleaning/separating our code as we move toward PSR-0 (http://www.php-fig.org/psr/psr-0/).
We have lots of different `features` that we would like to split up and organize in a way that makes the most sense.
We want: - Highly modular. - Easily extend/implement abstract code between features. - Outside the core framework.
Any suggested reading material, advice, or feedback would be fantastic!
Thanks HN! :)
Edit: We use CodeIgniter (earlier version)
6 comments
[ 34.7 ms ] story [ 63.0 ms ] thread[0]https://getcomposer.org
BAD:
* /var/www/config/mysql.json
* /var/www/static/site.css
* /var/www/index.php
* $_SERVER['DOCUMENT_ROOT'] = '/var/www';
GOOD:
* /var/www/config/mysql.json
* /var/www/public/static/site.css
* /var/www/public/index.php
* $_SERVER['DOCUMENT_ROOT'] = '/var/www/public';
/core/apps/[name of app]
/core/config/ (config files, PDF templates, etc.)
/core/inc/ [libraries/extensions]
/public_html/index.php
/public_html/info/ [icons, images, and other public accessible data]
mainly index.php has
$home = $_SERVER['SCRIPT_FILENAME'];
$loc = explode('/',$home);
define('CORE_BASE', implode('/',array_slice($loc,0,-2)).'/');
require_once core_BASE.'core/inc/main.php';
which defines the core path (below web root), then includes the main base code. From there all code is below web root.
note: css and javascript can be included directly (saves having browser request them anyway)