2012-06-18 63 views
-1

设置项目结构;我认为有一些“bootstrap.php”文件包含并设置了一切,比如数据库连接,会话管理,库,错误处理,会更好。或者仅仅包含当前所需的文件? (这将需要在包括等的顺序之前)。包含许多文件或仅包含一个文件

选择1:

的index.php

<?php 

include 'bootstrap.php'; 

//session... database up and ready to be used... 

备选方案2:

的index.php

<?php 
include 'session.php'; 
include 'database.php'; 
include 'errorhandling.php'; 
//now use database... 

回答

2

只包括所需要的特定的页面文件。例如,如果页面不需要数据库连接,则不会包含它。所以后一种方法更好地选择包括所需的文件,除非您在每个页面上导入一些常用的东西。