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?

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...