Page 1 of 1

Query::Include_Once() + Class File

Posted: Tue May 18, 2004 2:37 pm
by randomblink
Alright...
Prep For Question. ( This is a hypothetical question... )

I have a file: public_html / index.php
I have a class: public_html/libraries/classes/system/class_system.php
I have a class: public_html/libraries/classes/db/class_databaseaccess.php

In class_system.php I have a method...
->_IncludeDB

Code: Select all

<?php
function _IncludeDB()
{
    include_once( 'class_databaseaccess.php' );
}
?>
In index.php I am thinking of doing something akin to:

Code: Select all

<?php

include( '/libraries/classes/system/class_system.php' );

$basic = new system();

$basic->_IncludeDB();

$basic->...something or other database oriented...

?>
Ok...
I OBVIOUSLY need to give a PATH the Include to work... WHERE DO I SET THIS...?

Do I set the path IN the class? In the index.php?

I was thinking that since the class_system.php is the actual FILE that calls the INCLUDE statement, I would need to set the path to the class_databaseaccess.php file FROM the class_system.php file... But then I thought that since the CLASS was actually instantiated IN index.php, maybe the path needs to be set in Index.php...

Code: Select all

<?php

include_path( '/libraries/classes/system/' );
include( 'class_system.php' );

$basic = new system();

include_path( '/libraries/classes/db/' );
$basic->_IncludeDB();

$basic->...something or other database oriented...

?>
But I am unsure... And so I come to the smart-guys here on the forums... Any help would be appreciated... Thanks in advance...

Posted: Thu May 20, 2004 12:50 am
by jason
In an .htaccess file, you can put the following:

Code: Select all

php_value include_path .:/home/yourdir/public_html/libraries/classes/system/
That will set your include_path automatically.

Hm.

Posted: Thu May 20, 2004 9:24 am
by randomblink
Well, the problem is, I am working on a small, personally-built, cms. So I want something generic, not keyed to my system... So I really need something that would work on systems that don't offer HTACCESS...

Also, I HATE working with the HTACCESS files...
But THAT is another story...

Posted: Thu May 20, 2004 9:28 am
by jason
You could always use:

Code: Select all

include_once basedir(__FILE__).'/file.php';
The old basedir(__FILE__) trick.