Query::Include_Once() + Class File

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
randomblink
Forum Commoner
Posts: 51
Joined: Wed Jan 28, 2004 11:27 am
Location: Tulsa, Oklahoma, just this side of hell...
Contact:

Query::Include_Once() + Class File

Post 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...
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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.
randomblink
Forum Commoner
Posts: 51
Joined: Wed Jan 28, 2004 11:27 am
Location: Tulsa, Oklahoma, just this side of hell...
Contact:

Hm.

Post 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...
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

You could always use:

Code: Select all

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