Troubles with variables and Define()
So I've created many projects prior to this one without issue, but I'm
encountering a weird problem when it comes to accessing variables that
were Define()'d in my config.php. As an example, in index.php (without any
content) I have:
<!DOCTYPE html>
<html>
<?php require "config.php";
include PARTIALS."/head.php"; ?>
<body>
<?php include PARTIALS."/header.php"; ?>
<div id="content">
</div>
<?php include PARTIALS."/footer.php"; ?>
</body>
</html>
The head, header, and footer files are all properly included. However, if
I try to echo PARTIALS or SITE_ROOT, I get an error:
Notice: Use of undefined constant SITE_ROOT - assumed 'SITE_ROOT' in
C:\xampp\htdocs\robinson\partials\header.php on line 9
My config.php is as follows:
<?php
session_start();
ini_set( "display_errors", true);
define('SITE_ROOT', "http://localhost/robinson");
define('PARTIALS', SITE_ROOT."/partials");
define('DB_HOST', "localhost" );
define('DB_NAME', "local");
define('DB_USER', "localuser" );
define('DB_PASS', "localpass" );
?>
As I mentioned, I've created many test projects that follow the exact same
logic. And the weird part is that the pages are being properly included,
so the variable is "working" to an extent. I've compared my code against
"functioning" projects and haven't found any differences, so can anybody
explain what the issue might be?
Related Question
Assuming I don't route every page through index.php, is there a best way
to include config.php? I really don't want to have to manually change
pathnames to it in every subsequent page, nor include it on each of those
pages. So is there a best practice when it comes to doing this?
Thanks in advance.
No comments:
Post a Comment