Skip to main content
edited body
Source Link
65Fbef05
  • 419
  • 2
  • 12

I've been rolling around several ideas or approaches in my head, and none seem any more useful or "right" than another. I'm sure this is extremely objective but I'm looking for a close-to-definitive answer on the object oriented approach to large block string storage and output in PHP. Given the following example, how could I change my approach in a way that might cause Zeev Suraski to pat me on the back and say Mazel Tov (beside using HTML5)?

<?php

class OutputConstructor extends ContentRetriever // Or whatever I decide to name it
{

    protected $htmlHeadBlock;
    
    public function __construct()
    {
        
        $this->setHtmlHeadBlock();
        
    }
    
    protected function setHtmlHeadBlock()
    {
        
        ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

        <title><?php echo $this->pageTitle; ?></title>

        <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
        <link rel="icon" href="images/favicon.ico" type="image/x-icon" />

        <meta name="description" content="<?php echo $this->pageDescription; ?>" />
        <meta name="keywords" content="<?php echo $this->pageKeywords; ?>" />

        <link href="csstype="text/style.css" rel="stylesheet" type="texthref="css/style.css" />
        <script type="text/javascript" src="js/functions.js"></script>
    </head>
<?php
        $this->htmlHeadBlock = ob_get_clean();
        
    }
    
    public function getHtmlHeadBlock()
    {
        
        return $this->htmlHeadBlock;
        
    }

} // End of OutputConstructor

?>

The general theme I'm going with in this example class is that on construction, html is stored in a variable via output buffer and then returned by a public method. When evaluating this code, consider that the html will not be static. Page title, description, keywords and the such will be subbed out with dynamic property references. My overall question is: In object oriented programming, ideally where should the output be stored? PHP's DOMDocument class, however useful, doesn't really answer this question for me. Also in this instance, is there any best practice trade-off between using an output buffer and heredoc syntax? Thanks in advance for your guidance!

I've been rolling around several ideas or approaches in my head, and none seem any more useful or "right" than another. I'm sure this is extremely objective but I'm looking for a close-to-definitive answer on the object oriented approach to large block string storage and output in PHP. Given the following example, how could I change my approach in a way that might cause Zeev Suraski to pat me on the back and say Mazel Tov (beside using HTML5)?

<?php

class OutputConstructor extends ContentRetriever // Or whatever I decide to name it
{

    protected $htmlHeadBlock;
    
    public function __construct()
    {
        
        $this->setHtmlHeadBlock();
        
    }
    
    protected function setHtmlHeadBlock()
    {
        
        ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

        <title><?php echo $this->pageTitle; ?></title>

        <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
        <link rel="icon" href="images/favicon.ico" type="image/x-icon" />

        <meta name="description" content="<?php echo $this->pageDescription; ?>" />
        <meta name="keywords" content="<?php echo $this->pageKeywords; ?>" />

        <link href="css/style.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="js/functions.js"></script>
    </head>
<?php
        $this->htmlHeadBlock = ob_get_clean();
        
    }
    
    public function getHtmlHeadBlock()
    {
        
        return $this->htmlHeadBlock;
        
    }

} // End of OutputConstructor

?>

The general theme I'm going with in this example class is that on construction, html is stored in a variable via output buffer and then returned by a public method. When evaluating this code, consider that the html will not be static. Page title, description, keywords and the such will be subbed out with dynamic property references. My overall question is: In object oriented programming, ideally where should the output be stored? PHP's DOMDocument class, however useful, doesn't really answer this question for me. Also in this instance, is there any best practice trade-off between using an output buffer and heredoc syntax? Thanks in advance for your guidance!

I've been rolling around several ideas or approaches in my head, and none seem any more useful or "right" than another. I'm sure this is extremely objective but I'm looking for a close-to-definitive answer on the object oriented approach to large block string storage and output in PHP. Given the following example, how could I change my approach in a way that might cause Zeev Suraski to pat me on the back and say Mazel Tov (beside using HTML5)?

<?php

class OutputConstructor extends ContentRetriever // Or whatever I decide to name it
{

    protected $htmlHeadBlock;
    
    public function __construct()
    {
        
        $this->setHtmlHeadBlock();
        
    }
    
    protected function setHtmlHeadBlock()
    {
        
        ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

        <title><?php echo $this->pageTitle; ?></title>

        <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
        <link rel="icon" href="images/favicon.ico" type="image/x-icon" />

        <meta name="description" content="<?php echo $this->pageDescription; ?>" />
        <meta name="keywords" content="<?php echo $this->pageKeywords; ?>" />

        <link type="text/css" rel="stylesheet" href="css/style.css" />
        <script type="text/javascript" src="js/functions.js"></script>
    </head>
<?php
        $this->htmlHeadBlock = ob_get_clean();
        
    }
    
    public function getHtmlHeadBlock()
    {
        
        return $this->htmlHeadBlock;
        
    }

} // End of OutputConstructor

?>

The general theme I'm going with in this example class is that on construction, html is stored in a variable via output buffer and then returned by a public method. When evaluating this code, consider that the html will not be static. Page title, description, keywords and the such will be subbed out with dynamic property references. My overall question is: In object oriented programming, ideally where should the output be stored? PHP's DOMDocument class, however useful, doesn't really answer this question for me. Also in this instance, is there any best practice trade-off between using an output buffer and heredoc syntax? Thanks in advance for your guidance!

deleted 59 characters in body
Source Link
65Fbef05
  • 419
  • 2
  • 12
<?php

class OutputConstructor extends ContentRetriever // Or whatever I decide to name it
{

    protected $htmlHeadBlock;
    
    public function __construct()
    {
        
        $this->setHtmlHeadBlock();
        
    }
    
    protected function setHtmlHeadBlock()
    {
        
        ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

        <title>Welcome<title><?php Toecho My$this->pageTitle; Website!<?></title> 

        <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
        <link rel="icon" href="images/favicon.ico" type="image/x-icon" /> 

        <meta name="description" content="Imagine that you were on top of a mountain where you were attempting to chase a goat over a ledge. That's it; I've nothingcontent="<?php elseecho for$this->pageDescription; you."?>" />
        <meta name="keywords" content="key,words,allow,you,to,express,yourself,both,physically,and,emotionally"content="<?php echo $this->pageKeywords; ?>" /> 

        <link href="css/style.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="js/functions.js"></script>
    </head>
<?php
        $this->htmlHeadBlock = ob_get_clean();
        
    }
    
    public function getHtmlHeadBlock()
    {
        
        return $this->htmlHeadBlock;
        
    }

} // End of OutputConstructor

?>
<?php

class OutputConstructor
{

    protected $htmlHeadBlock;
    
    public function __construct()
    {
        
        $this->setHtmlHeadBlock();
        
    }
    
    protected function setHtmlHeadBlock()
    {
        
        ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Welcome To My Website!</title>
        <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
        <link rel="icon" href="images/favicon.ico" type="image/x-icon" />
        <meta name="description" content="Imagine that you were on top of a mountain where you were attempting to chase a goat over a ledge. That's it; I've nothing else for you." />
        <meta name="keywords" content="key,words,allow,you,to,express,yourself,both,physically,and,emotionally" />
        <link href="css/style.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="js/functions.js"></script>
    </head>
<?php
        $this->htmlHeadBlock = ob_get_clean();
        
    }
    
    public function getHtmlHeadBlock()
    {
        
        return $this->htmlHeadBlock;
        
    }

} // End of OutputConstructor

?>
<?php

class OutputConstructor extends ContentRetriever // Or whatever I decide to name it
{

    protected $htmlHeadBlock;
    
    public function __construct()
    {
        
        $this->setHtmlHeadBlock();
        
    }
    
    protected function setHtmlHeadBlock()
    {
        
        ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

        <title><?php echo $this->pageTitle; ?></title> 

        <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
        <link rel="icon" href="images/favicon.ico" type="image/x-icon" /> 

        <meta name="description" content="<?php echo $this->pageDescription; ?>" />
        <meta name="keywords" content="<?php echo $this->pageKeywords; ?>" /> 

        <link href="css/style.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="js/functions.js"></script>
    </head>
<?php
        $this->htmlHeadBlock = ob_get_clean();
        
    }
    
    public function getHtmlHeadBlock()
    {
        
        return $this->htmlHeadBlock;
        
    }

} // End of OutputConstructor

?>
added 114 characters in body; deleted 3 characters in body
Source Link
65Fbef05
  • 419
  • 2
  • 12

The general theme I'm going with in this example class is that on construction, html is stored in a variable via output buffer and then returned by a public method. When evaluating this code, consider that the html will not be static. Page title, description, keywords and the such will be subbed out with dynamic property references. My overall question is: In object oriented programming, ideally where should the output be stored? PHP's DOMDocument class, however useful, doesn't really answer this question for me. Also in this instance, is there any best practice trade-off between using an output buffer and heredoc syntax? Thanks in advance for your guidance!

The general theme I'm going with in this example class is that on construction, html is stored in a variable via output buffer and then returned by a public method. When evaluating this code, consider that the html will not be static. Page title, description, keywords and the such will be subbed out with dynamic property references. My overall question is: In object oriented programming, ideally where should the output be stored? PHP's DOMDocument class, however useful, doesn't really answer this question for me. Thanks in advance for your guidance!

The general theme I'm going with in this example class is that on construction, html is stored in a variable via output buffer and then returned by a public method. When evaluating this code, consider that the html will not be static. Page title, description, keywords and the such will be subbed out with dynamic property references. My overall question is: In object oriented programming, ideally where should the output be stored? PHP's DOMDocument class, however useful, doesn't really answer this question for me. Also in this instance, is there any best practice trade-off between using an output buffer and heredoc syntax? Thanks in advance for your guidance!

Source Link
65Fbef05
  • 419
  • 2
  • 12
Loading