SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: OOP question

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OOP question

    Been playing with a class that I found in a PHP book. It's working great...substitutes variables {varName} that I have in my template.inc file with the right content.

    The question I have is about swapping out a graphic based on the page the user is on. I have several nav buttons that are part of my template.inc file. They have rollovers on them that swap out the graphics, which is no problem as I just included that in the template, but I'd like to display the over state if the user is on the same page as the nav button. So if they are on the about us page the about us button is highlighted.

    How do go about making this happen in my class file?

    I assume you would replace the img src in the template file with a variable for each of the buttons, have the class do some type of check to see what page is being called up and input the right value?

    Any ideas.

    Thanks for your help.

    Ryan

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's the class if that's of interest:

    Code:
     <?php # HtmlTemplate.class
    // This class reads in a template, sets the different values, and sends it to the browser.
    class HtmlTemplate {
     // Set the attributes.
     var $template;
     var $html;
     var $parameters = array();
     function HtmlTemplate ($template) { // This function sets which template will be used.
      $this->template = $template;
      $this->html = implode ("", (file($this->template))); // Read the template into an array, then create a string.
     }
     function SetParameter ($variable, $value) { // This function sets the particular values.
      $this->parameters[$variable] = $value;
     }
     function CreatePage () { // This function does the bulk of the work.
      foreach ($this->parameters as $key => $value) { // Loop through all the parameters and set the variables to values.
       $template_name = '<!--{' . $key . '}-->';
       $this->html = str_replace ($template_name, $value, $this->html);
      }	
      echo $this->html;
     }
    }
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •