Jump to content

Creating HTML helper, need help!


spaze

Recommended Posts

Hello all!

 

I am developing an HTML helper for my own use and don't know exactly if I am doing the right thing.

 

I have a PHP script that includes a file called "helper.class" which contains class helper.

 

$html = new Helper;

$content .= $html->start();

$content .= $html->dotag( "body", array ( "class" => "myclass" ) );

 

in the Class Helper there is a function called start().

 

class Helper

{

  function start()

  {

      return "<html>";

  }

}

 

So the above would produce output of:

 

<html>

<body class="myclass">

 

My question is this:

 

Is there a way I could do this with following way:

 

$html = new Helper;

$html->start();

$html->dotag( "body", array ( "class" => "myclass" ) );

 

So in other words, can I call the functions in the class and add the results into a variable without using the $content .= portion?

 

Link to comment
https://forums.phpfreaks.com/topic/96875-creating-html-helper-need-help/
Share on other sites

you could but you would need to tweak the functions to add it to a global or global class variable,

 

eg:

 

class Helper
{
   function start()
   {
      return "<html>";
   }
}

 

would become:

 

class Helper
{
   function start()
   {
      Global $content;
      $content .= "<html>";
   }
}

 

hope this helps,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.