私のadmin.phpで私を設定$controller
し、動的CMSとしてうまく機能します。私が抱えている問題は、テンプレートとして使用しているファイルが認識されない$controller
ことです。
Admin.php
include_once("configuration.php");
require("cms.php");
$controller = new CMS();
...
$controller->template("body");
Cms.php
Class CMS{
/*New template function*/
function template($file){
if( isset($file) && file_exists($file.".php") ){
include_once($file.".php");
}else{
echo "";
}
}
/*Old template function*/
function template($file){
if(isset($file) && file_exists($file.".php")){
ob_start();
include($file.".php");
$template = ob_get_contents();
return $template;
} else {
echo "";
}
}
}
任意のテンプレート ページ
var_dump($controller);
反響するものNotice: Undefined variable: controller in
$controller
毎回呼び出さなくてもアクセスできるようになれば、もっと簡単になります。$controller
テンプレートページで未定義なのはなぜですか?
アップデート
私にとってうまくいくように見えたのは、そのようにvarを再度追加することです
Class CMS{
/*New template function*/
function template($file){
if( isset($file) && file_exists($file.".php") ){
$controller = $this;
include_once($file.".php");
}else{
echo "";
}
}
}
それは受け入れられますか?