Re: Invoking functions stored in a separate directory?
| From: | Clancy | Date: | Sat, 22 Aug 2009 07:31:55 +0000 |
| Subject: | Re: Invoking functions stored in a separate directory? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-297071@lists.php.net to get a copy of this message | ||
On Fri, 21 Aug 2009 15:16:11 +0200, akuhl@telkomsa.net ("Arno Kuhl") wrote:
>-----Original Message-----
>From: Clancy [mailto:clancy_1@cybec.com.au]
>Sent: 21 August 2009 01:26 PM
>To: php-general@lists.php.net
>Subject: [PHP] Invoking functions stored in a separate directory?
>
>I am developing an idea for a website engine which can be shared between
>several different websites. Each website would have its own directory under
>a common root directory, and the engine would be in a separate directory
>Engine:
>
>Root
>Website_1.com, Website_2.com, Engine
>
>The website directories would each contain the design data for that website,
>consisting basically of a mixture of text files and images. The various
>pages would be loaded by loading index.php from the website root directory,
>and specifying a number of parameters e.g.
>
>http://www.corybas.com/index.php?path=Holidays&level=0&item=0
>
>I have the minimum amount of code in index.php -- just enough to set some
>parameters to identify the website, and then include
>../Engine/Main_prog.php. This in turn can include any of a large number of
>other include files to carry out particular functions.
.....................................
>
>Using include ../Engine/Main_prog.php won't work for you in a production
>environment. You need to create a path.php file that defines the absolute
>path to the engine for each website, and include it at the top of your
>website script. Then you can do something like:
>
> include ENGINEPATH."Main_prog.php";
Thank you very much for this. It has at last provided the clue I was looking for, and
after far too long I have got a trivially simple demonstration working. One complication I
hadn't anticipated is that apparently I can only access functions in the include file, but
cannot execute any code in it.
Thus when Halla.php read:
<?php echo '<p>Eng_test_'.__LINE__.' Hallejuha!! : </p>'; ?>
and I included it:
$ok = define ('HOST_PATH','../Engine');
$ok = include (HOST_PATH.'/Halla.php');
nothing happened.
When Halla.php read:
<?php function halla ($i) {
echo '<p>Eng_test_'.__LINE__.' Hallejuha!! : '.$i.'</p>';
return $i; } ?>
and I included it:
$ok = define ('HOST_PATH','../Engine');
$ok = include (HOST_PATH.'/Halla.php');
$ok = halla (7);
echo '<p> Returned '.$ok'</p>';
it did work. I presume that this explains your next comment, in that I am neither reading
nor executing the code in the Include, so permissions don't come into it.
>You shouldn't really have permission problems as long as your website and
>engine are on the same server. ...
>One other advantage it will give you for your particualr design is that you
>can have multiple engines per server (e.g. Engine1, Engine2, etc) so that
>you can bring one engine down for upgrade while still keeping sites running
>on the other engines.
Yes; I have got already got all that working. Now I JUST have to convert my main program
into one big function!
Will I still be able to access $_GET & $_POST variables, and set up session variables from
inside this function? I guess I can declare them all GLOBAL?
Thanks, again,