Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...