私は functions.php ファイルを持っています。このファイルには、他の関数の中でも次のものが含まれています。
function head() {
global $brand, $brandName, $logo, $slogan, $siteName, $title, $titles, $keyword, $keywords, $description, $descriptions, $bodyclass, $bodyClass, $page;
include('_assets/inc/head.php');
}
function foot() {
global $brand, $brandName, $logo, $slogan, $siteName, $title, $titles, $keyword, $keywords, $description, $descriptions, $bodyclass, $bodyClass, $page;
include('_assets/inc/foot.php');
}
foot()
foot.php で呼び出していた変数を表示するために、globals 行を に複製する必要がありました。これらのグローバルを一元化する場所はないので、サイトにグローバル ラインを 1 回配置するだけで済みますか?
ジャックの指示に従って、私は今持っています:
class Page {
private $context;
public function __construct(array $context) {
$this->context = $context;
}
public function printHead() {
extract($this->context);
include '_assets/inc/head.php';
}
public function printFoot() {
extract($this->context);
include '_assets/inc/foot.php';
}
}
$page = new Page(array(
'brand' => 'myBrand',
'brandName' => '<span class="brand">'.$brand.' <sup><span aria-hidden="true" class="icon_search"></span></sup></span>',
'logo' => '<a href="/" class="brand">'.$brandName.'</a>',
'slogan' => '<span class="slogan">Find A Real Estate Professional</span>',
'siteName' => $logo.' | Directory of Real Estate Professionals',
'title' => 'Directory of Real Estate Professionals | '.$brand.'',
'titles' => array (
'home' => 'Find A Real Estate Professional | '.$brand.''
);
if(isset($titles[$page])){
$title = $titles[$page];
}
'keyword' => ''.$brand.', real estate professionals, real estate directory, real estate agents, realtor directory, real estate brokers, real estate lawyers, real estate insurance agents, real estate appraisers, real estate staging consultants',
'keywords' => array (
'' => ''
);
if(isset($keywords[$page])){
$keyword = $keywords[$page];
}
'description' => ''.$brand.' is a complete directory of real estate professionals, including agents, brokers, appraisers, insurance agents, stagers, lawyers, and more.',
'descriptions' => array (
'' => ''
);
if(isset($descriptions[$page])){
$description = $descriptions[$page];
}
'bodyclass' => ' page bbfix',
'bodyClass' => array (
'home' => 'home'
);
if(isset($bodyClass[$page])){
$bodyclass = $bodyClass[$page];
}
'page' => $page
));
$page->printHead();
$page->printFoot();
ただし、私のコードには配列に関連するエラーがあります。:(