Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Saj
    Saj is offline
    Regular Coder
    Join Date
    Feb 2003
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple Template Class

    Hey,

    I'm working on a simple template class at the moment to incorporate with my message board, but have stumbled on a few problems.....

    This is my code for the Error Template:

    PHP Code:
      class ErrorTemplate {
        function 
    ErrorTemplate($Error$MySQLError) {
          return <<<HTML
    <!-- My HTML -->
          HTML;
        }
      } 
    And my Error Function in my actual Message Board Class:

    PHP Code:
        function Error($Error$MySQLError '') {
          require(
    'Error.tpl.php');
          
    $ErrorTemplate = new ErrorTemplate($Error$MySQLError);
          return 
    false;
        } 
    Well first off, I get this error message:

    Parse error: parse error, unexpected $end in c:\web\www\php\mb\mysql class\phpWWWBoard\Error.tpl.php on line 29

    Fatal error: Cannot instantiate non-existent class: errortemplate in c:\web\www\php\mb\mysql class\phpWWWBoard\phpWWWBoard.php on line 51
    However, it seems that when I remove the spaces before return <<<HTML and HTML;, the error goes away, but the HTML doesnt show up. I have not been able to get any of the HTML to show up, actually, and can't see what I'm doing wrong.

    Any help would be appreciated.
    - Saj

  • #2
    New Coder
    Join Date
    Oct 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm i am going to need more of error.tpl.php to know what's going on..
    class ErrorTemplate {
    function ErrorTemplate($Error, $MySQLError) {
    return <<<HTML
    <!-- My HTML -->
    HTML;
    }
    }
    feels wrong.. return <<< HTML ?..
    try
    class ErrorTemplate {
    function ErrorTemplate($Error, $MySQLError) {
    $HTML.= "<!-- My HTML --> HTML....";
    return $HTML;
    }
    }

    this should work.. i don't know what are you doing with return <<< HTML
    (maybe add a echo $HTML; also.. )

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    If you are going to use heredoc syntax then you need to make sure you set it up properly. In your case you would be better off storing the the value of your heredoc statement in a variable and then returning the variable.

    PHP Code:

    class ErrorTemplate {
        function 
    ErrorTemplate($Error$MySQLError) {
            
    $html =  <<<HTML
    <!-- My HTML -->
    HTML;
            return 
    $html;
        }

    Note when using heredoc syntax the ending command must be flush up against the left side. Or in other words it must be the first thing on that line with no spaces before it.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

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