FreeBenzine Posted September 9, 2011 Report Posted September 9, 2011 Hi, My index.php consists of several Includes associated with several DIVs and each Include file is a php file located at a sub-folder. Typically an include file looks like: <div id="CentralDiv"> <?php include ("Research/Publication/MainDIV/IncludeMain.php"); ?> </div> <div id="RightDiv"> <?php include ("Research/Publication/RightDIV/IncludeRight.php"); ?> </div> <div id="FooterDiv"> <?php include ("Research/Publication/FooterDIV/IncludeFooter.php"); ?> </div> As I am in the beginning stage of the design so I do not know for sure the folder/page name that will be there finally. So I want to use the pathnames as variables stored in a file 'MyVar.inc.php' - so that if page names are changed then I do not have to edit all the index.phps. I understand that one option would be to have include("MyVar.inc.php") in every time I call an Include - but that does not sound smart. Is there a way that I can call all the variables stored in MyVar.inc.php anywhere in the index.php? How can I use variables stored in MyVar.inc.php for <Title> and <body id= > ? ALSO: Is it a right approach in web design - or I am making some mistakes? Any help will be appreciated. Quote
falkencreative Posted September 9, 2011 Report Posted September 9, 2011 This seems like an unnecessarily complicated approach. I'd suggest only using includes for code that's going to be repeated. For example, it mades sense to use includes for items like the header, footer and navigation, but it may not make sense to use an include just for the main page content, if that is only going to be used on a single page. If it is only used once, you may as well place it within the main index.php page. In regards to your question, could you just have one global .php file that sets up all of the PHP variables required for your paths? If you include that file at the top of every .php file, you should have access to all of those variables throughout the file. How can I use variables stored in MyVar.inc.php for <Title> and <body id= > ? Same way you would use any other variables. If you include the MyVar.inc.php file before all the other includes, you can use the variables within MyVar.inc.php within all other includes on the page. Quote
FreeBenzine Posted September 11, 2011 Author Report Posted September 11, 2011 Thanks. I called the file MyVar.inc.php containing my variables as: <title> <?php include ("CSS/MyVar.inc.php"); echo $Page4_2Title; ?> </title> but sadly I cannot get the php variables in subsequent lines of the same index.php. Am I making any mistake? Quote
falkencreative Posted September 11, 2011 Report Posted September 11, 2011 That should work -- it works in my own tests. Are you sure the path is correct and the file is being properly included? You might try echoing something out within MyVar.inc.php to confirm it is being included correctly. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.