Set Up root path constant

Discuss general development subjects that are not specific to a particular version like the versioning control system we use or other infrastructure.
Post Reply
leandrojunior7
Registered User
Posts: 4
Joined: Wed Dec 14, 2011 10:49 pm

Set Up root path constant

Post by leandrojunior7 »

:D Hello, I am studying the code of phpBB, virtually all of the files have this code at the beginning of the file, my question is as follows:

How the php know that PHPBB_ROOT_PATH refers to the root directory where the files and directories are on the forum.
It seems to me that is a constant set to root, but where is it defined?, for example I wanted to change the PHPBB_ROOT_PATH to PHPBB_HOME

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);


Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: Set Up root path constant

Post by Oleg »

I think you are meant to define it before including phpbb's source, this assumes you are using phpbb in your own script somehow.

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Berlin, Germany
Contact:

Re: Set Up root path constant

Post by naderman »

Yes, typically this would just assume ./ which is at the end of the expression. But if you include phpBB in another PHP application you can use the constant to overwrite that value.

leandrojunior7
Registered User
Posts: 4
Joined: Wed Dec 14, 2011 10:49 pm

Re: Set Up root path constant

Post by leandrojunior7 »

OK , but I wanted to understand how the constant PHPBB_ROOT_PATH is defined to ./, because there is a folder INCLUDES that have a file called constants.php that lists over all constants used for, but , PHP_ROOT_PATH is an comentary that says 'valid external constants'

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1904
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: Set Up root path constant

Post by DavidIQ »

It isn't defined unless you specifically define it. In the code snippet you posted it's checking for it being defined, not assigning it the value "./"
If you need to define it then you do so in the constants.php file.
Image

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Berlin, Germany
Contact:

Re: Set Up root path constant

Post by naderman »

You cannot define it in constants.php because it's needed before constants.php is loaded.

leandrojunior7
Registered User
Posts: 4
Joined: Wed Dec 14, 2011 10:49 pm

Re: Set Up root path constant

Post by leandrojunior7 »

So, the conditional always returns false cause its not defined any constant called PHPBB_ROOT_PATH.

Code: Select all


<?
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
?>
 
Is it tha same thing following?

Code: Select all

<?
$phpbb_root_path = './';

?>


User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Berlin, Germany
Contact:

Re: Set Up root path constant

Post by naderman »

Yes, unless you set the constant before you include the PHP file

leandrojunior7
Registered User
Posts: 4
Joined: Wed Dec 14, 2011 10:49 pm

Re: Set Up root path constant

Post by leandrojunior7 »

Okay ,im little confused, but thats okay,

THANKS! :)

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: Set Up root path constant

Post by imkingdavid »

leandrojunior7 wrote:Okay ,im little confused, but thats okay,

THANKS! :)
Where's the confusion?

PHPBB_ROOT_PATH is a constant that is undefined in a traditional phpBB installation. As long as it is undefined, $phpbb_root_path is always set to "./". However, PHPBB_ROOT_PATH can be used by an external application to overwrite the default value of $phpbb_root_path without requiring edits to the phpBB files (as long as it is defined before they are used).

For instance:

Code: Select all

// my_external_script.php
// phpBB isn't at ./ but I need to include the phpBB files. Oh no, what do I do?
// Oh yeah, I can just define PHPBB_ROOT_PATH. Hurrah!
define('PHPBB_ROOT_PATH', './path/to/phpbb/'); // remember the trailing /
// Okay, now we can include a phpBB file without fear or breakage
include(PHPBB_ROOT_PATH . 'phpbb_file.php');
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

Post Reply