Relative vs. Absolute Paths in Overall Header/Functions.php

Discussion forum for MOD Writers regarding MOD Development.
User avatar
Jackanape
Registered User
Posts: 1076
Joined: Wed Oct 13, 2004 6:01 am
Location: Capitol of the Great State of New York
Name: Jack Drury

Relative vs. Absolute Paths in Overall Header/Functions.php

Post by Jackanape »

So, this has been bugging me for a while, and I simply solved the issue with absolute path calls, but I'm wondering if there's a more elegant solution.

I've modified my overall header to include outside files, such as calendar displays, etc. I'v done this via functions.php, adding a new template variable, like this:

Code: Select all

$output11 = file_get_contents('../shtml/footmenu.shtml');	
This relative path works fine, until I try to login to the Admin Panel, when I get a "no file found in that location" error. Now, obviously, this is because the admin login is in a subfolder of the root folder, so in the past I simply went with an absolute path.

However, I'm in the middle of some heavy testing on my local dev server, and I want to work with relative paths again. Instead of changing back and forth, is there a better solution to this?

It's not a world ender, but it is a bit niggling, and I hate loose ends...LOL

Anyone else with the same nagging problem?
Last edited by Mick on Thu Apr 23, 2015 10:47 am, edited 1 time in total.
~Extending the rule of meticulous exactitude to exaspirating punctillio...still.~
Treat your phpBB like a member of the family--Update and MOD her by hand, with HTML-Kit
: : Wanna Talk Poker? : : Image : :
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26874
Joined: Fri Aug 29, 2008 9:49 am

Re: Relative vs. Absolute Paths in Overall Header/Functions.php

Post by Mick »

You should read: Are You In the Right Place?

I'll move this for you.
  • "The more connected we get the more alone we become” - Kyle Broflovski© 🇬🇧
User avatar
Jackanape
Registered User
Posts: 1076
Joined: Wed Oct 13, 2004 6:01 am
Location: Capitol of the Great State of New York
Name: Jack Drury

Re: Relative vs. Absolute Paths in Overall Header/Functions.php

Post by Jackanape »

Thank you. I gave this some consideration, too, before posting. It's not a style issue, and I didn't think it was a Mod writer's question, as it's more of question relating to phpbb3 and its use of relative paths.

Oh, well, not the first time I've been wrong.

So...any mod writers left, or has everyone gone over to extensions?
~Extending the rule of meticulous exactitude to exaspirating punctillio...still.~
Treat your phpBB like a member of the family--Update and MOD her by hand, with HTML-Kit
: : Wanna Talk Poker? : : Image : :
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53569
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Relative vs. Absolute Paths in Overall Header/Functions.php

Post by Brf »

Look at the way the existing includes in phpBB work.
They are always relative to $phpbb_root_path

Code: Select all

include($phpbb_root_path . 'common.' . $phpEx);
User avatar
Jackanape
Registered User
Posts: 1076
Joined: Wed Oct 13, 2004 6:01 am
Location: Capitol of the Great State of New York
Name: Jack Drury

Re: Relative vs. Absolute Paths in Overall Header/Functions.php

Post by Jackanape »

Brf wrote:Look at the way the existing includes in phpBB work.
They are always relative to $phpbb_root_path

Code: Select all

include($phpbb_root_path . 'common.' . $phpEx);
Of course! D'oh!

So, if I'm including something higher in the site heirarchy, I'd do:

Code: Select all

include('../' . $phpbb_root_path . 'common.' . $phpEx);
I really can't believe I haven't asked this before, and never even considered this!

Cheers, Brf, and thanks, I'm off to fiddle with it now!
~Extending the rule of meticulous exactitude to exaspirating punctillio...still.~
Treat your phpBB like a member of the family--Update and MOD her by hand, with HTML-Kit
: : Wanna Talk Poker? : : Image : :
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53569
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Relative vs. Absolute Paths in Overall Header/Functions.php

Post by Brf »

Jackanape wrote:

Code: Select all

include('../' . $phpbb_root_path . 'common.' . $phpEx);
No. I think it would be

Code: Select all

include($phpbb_root_path . '/../common.' . $phpEx);
but I might be wrong, since $phpbb_root_path is usually a relative path . Try it both ways.
User avatar
Jackanape
Registered User
Posts: 1076
Joined: Wed Oct 13, 2004 6:01 am
Location: Capitol of the Great State of New York
Name: Jack Drury

Re: Relative vs. Absolute Paths in Overall Header/Functions.php

Post by Jackanape »

There it is:

Code: Select all

$output11 = file_get_contents($phpbb_root_path . '../shtml/footmenu.shtml');
Works like a champ! Thanks for helping get my head on straight, Brf!
~Extending the rule of meticulous exactitude to exaspirating punctillio...still.~
Treat your phpBB like a member of the family--Update and MOD her by hand, with HTML-Kit
: : Wanna Talk Poker? : : Image : :

Return to “[3.0.x] MOD Writers Discussion”