Forum Moderators: coopster
In a php script, I'm instantiating a class (Page) as an object. The way the script works is that I create a new page name in a form, and on submit, the script generates a new file with this code (fictitious example marmalade):
<?phpinclude "classes/page.class1.php"; // The HTML page template.
$marmalade = new Page;
(code)
$marmalade->ThisPage = "marmalade";
$marmalade->SetContent($content);
$marmalade->Template();?>
"marmalade" is an example name of the page, and each time I run the form I can create a new page with a new pagename - "jam", "honey", etc. The Page class is an HTML template. All this works well, and I'm creating my new pages no problem.
Where I've got stuck is the navigation menu. I'm also using a class (Button) which I instantiate as an object each time I use a menu-building form, which on submit, generates a new navigation button which is added to the previous ones. The output script is like this (eg):
</php
include ('classes/makebutton.class.php');
?>
<?php
$jam = new Button;
$jam->ThisPage2 = "jam";
$jam->Template2();
?>
<?php
$marmalade = new Button;
$marmalade->ThisPage2 = "marmalade";
$marmalade->Template2();
?>
<?php
$honey = new Button;
$honey->ThisPage2 = "honey";
$honey->Template2();
?>
This work fine as well, but what I want is for the navigation button not to be an actual link but plain text when the user is on that page. So I am trying to somehow compare 'ThisPage' against 'ThisPage2' in the makebutton.class, the code for which is:
<?php/* We want to create button objects using this HTML template, and each time a button is created the object is added to the file "menu.php". The process is exactly the same as the Page class. */
class Button {
// Create required variables
var $ThisPage;
var $ThisPage2;
var $LinkText;// Navigation button template
function Template2() {
// Compares current page with new variable - but how?
if ($this->ThisPage2 == $ThisPage) {
echo '<li><strong>' . $this->LinkText . '</strong></li>';
} else {
echo '<li><a href="' . $this->ThisPage2 . '.php" title="' . $this->LinkText . '">' . $this->LinkText . '</a></li>';
}
echo "\n";
}// The functions that populate the above
function DisplayThisPage() {
echo $ThisPage;
}function DisplayThisPage2() {
echo $this->ThisPage2;
}function DisplayLinkText() {
echo $this->LinkText;
}}
?>
I can't seem to retrieve into this last script the value of the outside variable 'ThisPage' (from the Page object). The concept is that if ThisPage = "marmalade" and ThisPage2 = "jam" then the above script writes a button with a link. But if they are both "marmalade" there will be no link.
Apologies for the long post, but I'm new to objects and unless I explain what I've done it seems rather pointless. Any assistance would be appreciated.