0

I use some constants like PATH_ROOT, PATH_TEMPLATES, etc among all my project.

Is there an alternative to make them available other than include/require a config.php file in each script of my project.

I'm talking about a project witch doesn't make use of any framework.

javier_domenech
  • 5,995
  • 6
  • 37
  • 59
  • 1
    Have you considered options like php.ini's `auto_prepend_file`? – Niet the Dark Absol Jun 17 '16 at 10:25
  • 2
    Then again, surely you have some kind of "startup" script, that establishes database connection, class autoloaders, etc...? – Niet the Dark Absol Jun 17 '16 at 10:26
  • startup script? Nope, my connection for instance is entirely managed by a Class I created, which has private attributes or constants like database, password, etc.. – javier_domenech Jun 17 '16 at 10:29
  • Well sure, but how are you giving your script access to that class you created? – Niet the Dark Absol Jun 17 '16 at 10:29
  • I use require_once('MyDBClass") – javier_domenech Jun 17 '16 at 10:30
  • So since you're already using `require_once`, you have two options. Either simply add another `require_once` to your config file, *or* change the `require_once` to something like `startup.php`, which itself `require`s other files or defines constants. – Niet the Dark Absol Jun 17 '16 at 10:32
  • Im in agreement with the others.. Most modern frameworks use a bootloader, this is usually an index.php file (or at least where it starts). This is where your constant script should be required so that it is available everywhere. – mic Jun 17 '16 at 10:32
  • I know guys, I've already used something like that with Laravel. But the project I'm talking about it's entirely handmade, no framework at all, and it's a big one (running online for 7 or 8 years). I don't know of to manage for doing that on this project. – javier_domenech Jun 17 '16 at 10:33
  • (I think the phrase mic is looking for here is "front controller" which is something of a lifestyle choice). Voting to close this as vivoconunxino has described an unacceptable solution to the problem but not given any indication of what criteria the solution should fulfill nor the contect of how this information is managed. – symcbean Jun 17 '16 at 10:36
  • ok @symcbean do whatever you think is right. If you need any extra info you can ask too – javier_domenech Jun 17 '16 at 10:39
  • Does this question / answer help you maybe? http://stackoverflow.com/questions/6374495/create-arbitrary-values-in-php-ini – Aurel Bílý Jun 17 '16 at 10:48
  • Can you show your project structure?? – Mehul Kuriya Jun 17 '16 at 10:50
  • what about getenv('PATH_TEMPLATES')? and define `PATH_TEMPLATES` in apache.conf? – Muhammad Shahzad Jun 17 '16 at 10:51
  • 1
    @Aurel yep, partially because I agree with the ones who advise to not put project variables on a ini file wich its for all the phps. But I'd go with that at the moment. #Mehui Kuriya, 979 folders.. I can't. #Muhammad Shahzad that's almost the same solution as Aurel provided, thanks. – javier_domenech Jun 17 '16 at 10:58

0 Answers0