1.使用PHP中require如何包含一个文件夹中的所有文件?
require("./folder/*")是不行的,难道PHP中不能像Java中的include一样灵活方便吗?
不能正则识别名称吗?模式识别?2。不用require同一个类两次?
file name: A_Dao.class.php
function: contain basic operations of A.class
A_Dao.class.php
<?php
require("DBConnection.class.php");
...
...
...
?>another file: B_Dao.class.php
function: contain basic operations of B.class
B_Dao.class.php
<?php
require("DBConnection.class.php");
...
...
...
?>A and B.class are entities as abstracted from conceptions.ServiceA.class.php
<?php
require("./dao/A_Dao.class.php");
require("./dao/B_dao.class.php");
...
...
...
?>
run ServiceA.class.php
"Fatal error: Cannot redeclare class DBConnection in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\application\dao\DBConnection.class.php on line 3"What's wrong?
为什么不能重复require相同的(DBConnection.class.php)?
编译器不会总动处理吗(像Java一样)?
require("./folder/*")是不行的,难道PHP中不能像Java中的include一样灵活方便吗?
不能正则识别名称吗?模式识别?2。不用require同一个类两次?
file name: A_Dao.class.php
function: contain basic operations of A.class
A_Dao.class.php
<?php
require("DBConnection.class.php");
...
...
...
?>another file: B_Dao.class.php
function: contain basic operations of B.class
B_Dao.class.php
<?php
require("DBConnection.class.php");
...
...
...
?>A and B.class are entities as abstracted from conceptions.ServiceA.class.php
<?php
require("./dao/A_Dao.class.php");
require("./dao/B_dao.class.php");
...
...
...
?>
run ServiceA.class.php
"Fatal error: Cannot redeclare class DBConnection in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\application\dao\DBConnection.class.php on line 3"What's wrong?
为什么不能重复require相同的(DBConnection.class.php)?
编译器不会总动处理吗(像Java一样)?
require会把目标文件全部插入当前文件。如果允许了*,目录下所有文件都会被插入进来,这样,文件会超级大。第二个问题:
require_onceC/C++都有不允许重复include同一个文件。
但是我针对每一个实体对象都写了一个对应的操纵数据的类
这样我在一个业务中需要处理所有的实体对象,进行数据库的insert和select
实体对象有14个,相应的DAO class有14个
我以前是用java,Structs框架就是这样分层的
不过我现在使用的我称之为MV
folders:
entities: contain all the entity classes
dao: contain all the database access objects according to every entity
service: use dao and entitises to complete tasks
我第一次使用PHP,不知道大家使用PHP都是如何系统分层的?如何设计的?
在我的博客里我写了问题,有兴趣的可以帮助、探讨一下
————————————————————————————————
勋章啊……我啥时候也能得到这些……
————————————————————————————————
基于CSDN论坛提供的插件扩展功能,自己做了个签名档工具,分享给大家,欢迎技术交流 :)