duanhao5038 2016-10-16 21:47
浏览 11
已采纳

包含实例和文件的最佳方法是什么?

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.

  • 写回答

1条回答 默认 最新

  • dongxun4110 2016-10-16 22:15
    关注

    instead of require use require_once

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题