如何使用OOP设置扩展公共变量的动态标题


How to set dynamic title to extended public variable with OOP?

我希望有人能帮助我。我如何通过扩展原始类来最好地动态更改页面标题、desc或key vs.vs?以下是我目前所拥有的:

<?php
class siteGlobal
    {
        public $arr = array('title'=>'Page Default title','desc'=>'Page default     description');
        public function pageHeader()
            { ?>
<!doctype html><html>
    <?php   }
        public function metaTags()
            { ?>
<head>
<meta charset="utf-8">
<title><?php echo $this->arr['title'];?></title>
<meta name="description" content="<?php echo $this->arr['desc'];?>">
   <?php    }
        public function pageBody()
            { ?>
</head>
<body>
    <?php    }
        public function pageFooter()
            { ?>
</body>
</html>
    <?php    }
} ?>

其他页面

require_once('siteGlobal.php');
class pageDetail extends siteGlobal
    {
        public function __construct()
            {
                $this->pageHeader();
                $this->newMetas();
                $this->startBody();     
                $this->sayfaBilgileri();
                $this->pageFooter();
            }
        public function newMetas()
            {
                parent::metaTags();
            }
        public function sayfaBilgileri()
            {
                //HOW I can write a new title and description in this function to siteGlobal.php (public $metaInfo) ?>
<div style="width:640px; margin:0 auto;">
<h1>Page New Title</h1>
<h2>Page New Subtitle</h2>
<p>Lorem Ipsum, bla bla....</p>
</div>
    <?php    }
    }
$writePage = new pageDetail(); ?>

您可以尝试在父类中创建一个方法,比如:

protected function setTitle($title){
    $this->arr['title'] = $title;
}

并以这种方式在扩展类中使用它:

parent::setTitle("My title");