Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2012-12-09 17:05:11

BangoFace
Member
Registered: 2012-08-01
Posts: 47

PHP document root

Within FluxBB, I'm making use of the following to make an in-theme template for separate pages/articles.

<?php
define('PUN_ROOT', dirname(__FILE__).'/');
require PUN_ROOT.'include/common.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
$page_title = array(pun_htmlspecialchars($pun_config['o_board_title']));
define('PUN_ALLOW_INDEX', 1);
define('PUN_ACTIVE_PAGE', 'index');
require PUN_ROOT.'include/header.php';
?>
<div>
Site content
</div>
<?php require PUN_ROOT.'include/footer.php';?>

This works fine with files in the document root, they all have a correct header, footer and formatting to match the site theme.

Now when I use this for files in a new directory, it cannot find the required includes. To get around this, I've altered the 'define' to include the document root like so:

<?php
define('PUN_ROOT',$_SERVER['DOCUMENT_ROOT'].'/');
require PUN_ROOT.'include/common.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
$page_title = array(pun_htmlspecialchars($pun_config['o_board_title']));
define('PUN_ALLOW_INDEX', 1);
define('PUN_ACTIVE_PAGE', 'index');
require PUN_ROOT.'include/header.php';
?>

<div>
Site content
</div>
<?php require PUN_ROOT.'include/footer.php';?>

This solved the problem, however it has now lost contact with the .css file and thus has no formatting.

How do I fix this?

Last edited by BangoFace (2012-12-09 17:05:50)

Offline

#2 2012-12-09 18:08:10

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 5,720
Website

Re: PHP document root

You should use a relative path instead.

So if your document root is /path/to/forum, in the file /path/to/forum/subdir/index.php, you'd define PUN_ROOT like this:

define('PUN_ROOT', '../');

This is how it is done throughout the core.


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#3 2012-12-09 18:25:29

BangoFace
Member
Registered: 2012-08-01
Posts: 47

Re: PHP document root

That works better (and also now works on localhost).

Still got the same problem with the stylesheet link though? It's probably something I need to add in; does the header.php pull it in and now I need to change the document path in that to a relative one?

(edit: site images (logo) also not found)

Last edited by BangoFace (2012-12-09 18:27:29)

Offline

Board footer

Powered by FluxBB 1.5.6