I am working on a php application. I have many classes and files divided into different directories. I have a config file that holds the database connection settings and files with require
. For example:require "core/application.php"
and I do this for all my classes and files. config.php
also creates my objects. I tried to require config.php
in all my files so that my classes would have access to the objects in config.php
but it tries to create another object and I get and error saying that the object already exists. I also tried to create an init()
function and call it in my index.php
but then I get an error saying that init()
already exists. I was trying to auto load my classes but I don't think that is going to work. I have been trying different things for the past few days but I cannot figure anything out. I also don't want to pass my classes the objects. Thank you for the help.
包含实例和文件的最佳方法是什么?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- dongxun4110 2016-10-16 22:15关注
instead of
require
userequire_once
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报