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
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
- ¥15 孟德尔随机化怎样画共定位分析图
- ¥18 模拟电路问题解答有偿速度
- ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
- ¥15 误删注册表文件致win10无法开启
- ¥15 请问在阿里云服务器中怎么利用数据库制作网站
- ¥60 ESP32怎么烧录自启动程序
- ¥50 html2canvas超出滚动条不显示
- ¥15 java业务性能问题求解(sql,业务设计相关)
- ¥15 52810 尾椎c三个a 写蓝牙地址