Hi
OOP is new to me, and the manual has not helped me on this one:

What am I doing wrong?  I am getting an error message about calling an undefined 
function.  I defined the method (function) in the class definitions, but when I create 
an instance, I get the error message mention above.

By the way, I tested the function by embedding it inside some html coding, and it 
worked.

Evidently, I still don't understand the OOP process.  Can someone point me in the 
right direction?  Below, please find my coding listed as CLASS DEFINITIONS(1 and 2), 
INSTANCE, AND HTML : ( I did not include the .css file)

CLASS DEFINITIONS (1):
<?php
//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 IdentifyTemplate ($template) {
  //This function sets which template will be used.
    $this->template = $template;
  }
  

  function SetParameter($variable,$value) {
  //This function sets the particular values.
    $this->parameters[$variable] = $value;
  }



  function CreatePage() {
  //This function does the bulk of the work.
    $this->html = implode ("",(file($this->template))); //Read the template into an 
array, then
                                                         //create a string.

    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;
  }
}
?>

CLASS DEFINITION (2): //***THE PrintImage FUNCTION GIVES ME THE ERROR MESSAGE***
<?php
//This class is an extension of the HtmlTemplate class.
//It adds the print_image funcion which calls the make_image function.
//These two functions combined print an IMG tag for a given file.

class HtmlTemplateImages extends HtmlTemplate {

//No attributes are necessary because of existing ones in parent class.

function MakeImage($file, $alt=false, $align=false, $extras=false, $dir=false,
                    $border=0) {
  global $size, $image;
                global $HTTP_SERVER_VARS;
  if (!$dir) {
      $dir = 'images';
  }
  if ($size = @getimagesize($HTTP_SERVER_VARS['DOCUMENT_ROOT'].$dir.'/'.$file)) {
      $image = sprintf('<img src="%s/%s" border="%d" %s ALT="%s" %s%s >',
     $dir,
     $file,
                   $border,
     $size[3],
     ($alt    ? $alt : ''),
     ($align  ? ' align="'.$align.'"'  :''),
     ($extras ? ' '.$extras           :'')
   );
  } else {
      $image = sprintf('<img src="%s/%s" border="%d" ALT="%s" %s%s >',
     $dir,
     $file,
     $border,
     ($alt    ? $alt  : ''),
     ($align  ? ' ALIGN="'.$align.'"'  : ''),
     ($extras ? ' '.$extras            : '')
   );
  }
  return $image;
 }

function PrintImage($file, $alt=false, $align=false, $extras=false, $dir=false,
                     $border=0) {
             
      print MakeImage($file, $alt, $align, $extras, $dir);
}
}
?>

INSTANCE:
<?php
//This is a sample page that uses the HtmlTemplate class and the child class 
HtmlTemplateImages.


require_once "HtmlTemplate.inc"; //Include the parent class.
require_once "HtmlTemplateImages.inc"; //Include the child class.

$page = new HtmlTemplate(); //Create an instance.

$page->IdentifyTemplate ("EjebTemplate.inc");  //Identify the template to use for this
                                               //application.

$page->SetParameter ("CSS_LINK", "ejebstyle.css");
$page->SetParameter ("EJEB_LOGO", $page->PrintImage('topgrey.jpg', 'EJEB'));

$page->SetParameter ("EJEB_SOLUTIONS", "eJeb Solutions");

$page->CreatePage(); //Send the page to the browser.

?>

HTML:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel=stylesheet href="{CSS_LINK}" type="text/css">

</head>

<body>
<table width="720" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td height="50" colspan="3" valign="top">{EJEB_LOGO}</td>
    <td colspan="2" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td colspan="4" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
  </tr>
  <tr> 
    <td width="120" height="25" valign="top"><p>{EJEB_SOLUTIONS}</p></td>
    <td colspan="3" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td colspan="2" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td colspan="2" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td width="180" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
  </tr>
  <tr> 
    <td height="25" colspan="3" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td colspan="4" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td colspan="2" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
  </tr>
  <tr> 
    <td colspan="2" rowspan="4" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td colspan="5" rowspan="3" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td height="50" colspan="2" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
  </tr>
  <tr> 
    <td height="50" colspan="2" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
  </tr>
  <tr> 
    <td height="50" colspan="2" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
  </tr>
  <tr> 
    <td colspan="5" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td width="60" height="450"></td>
    <td></td>
  </tr>
  <tr> 
    <td height="0"></td>
    <td width="80"></td>
    <td width="40"></td>
    <td width="60"></td>
    <td width="60"></td>
    <td width="60"></td>
    <td width="60"></td>
    <td></td>
    <td></td>
  </tr>
</table>

</body>
</html>

Reply via email to