Forum Moderators: coopster

Message Too Old, No Replies

configuring the 3rdparty config file

         

PHPycho

10:53 am on Dec 30, 2009 (gmt 0)

10+ Year Member



Hello forums!

I need your suggestion in the following case.

I have some 3rdparty script which have its own configuration file(say config.php) for db settings, folder dir, base url etc.
I want to use it my framework and want to use the framework Db settings, folder settings, url settings to the 3rd party config file.

Generally 3rd party has some folders and generally includes the config.php file @ the top.
for example: 3rdparty/libs/someapplication.php

[PHP]<?php
include('../includes/config.php');
.......[/PHP]

What i want is: i want to include my framework config file @ the top so that i can re-use the variables.

For example:
3rdparty/includes/config.php
[PHP]<?php
include('../../my_framwork_includes/config.php');
//use framework settings here...
....[/PHP]

and will be using this config.php to 3rdparty application files.

This works only for application files under 3rdparty/libs/... but wont work if the files are in the base or some other nested folder and the reason is obvious.

How to deal in such case so that the 3rdparty/includes/config.php file can be used along with the framework config vars.

Thanks in advance for the valueable suggestion.
Regards

rocknbil

6:49 pm on Dec 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



and the reason is obvious.

But obvious for the reasons you think? :-)

When you do this,

include('../../my_framwork_includes/config.php');

You're stuck with that relative structuring. This will haunt you all through your system, and lock you to the "toothpick syndrome" on all your paths.

Wherever you form any include, do this:

include($_SERVER['DOCUMENT_ROOT'] . '/my_framework_includes/config.php');

or

include("$_SERVER[DOCUMENT_ROOT]/my_framework_includes/config.php");

Or define the doc root as a constant, use it.

Wherever you're calling it from, it will find it.

PHPycho

8:48 am on Dec 31, 2009 (gmt 0)

10+ Year Member



"Or define the doc root as a constant, use it. "
How could you use constant at the first go.
first you have to include the file with constants then only you can use that constant, isn't it?

coopster

3:06 pm on Dec 31, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



have a look at the PHP auto_prepend_file [php.net] configuration directive. Might meet your needs.