실행해야하는 파일과 동일한 파일에서 템플릿 엔진을 실행하므로 {username}과 같은 것을 만드는 템플릿 엔진이 있습니다. HTML의 PHP 변수는 그 것을 처리하는 모든 것과 같은 페이지에 있어야합니다. 하지만 그렇게하려고하면 클래스가 이미 오류라고합니다.이 오류를 수정하려고 시도했지만 이것이 가장 가까운 오류입니다.이 오류를 수정하려면 어쨌든 있습니까? 여기 내 코드 :PHP 클래스가 이미 호출되었는지 확인
<?php
//error_reporting(0);
if(in_array('NewTemplateHandler', get_declared_classes()))
{
$template = new NewTemplateHandler("test4.php");
$template->output();
//echo "Template has not been called";
}else
{
echo "Else called";
}
class NewTemplateHandler
{
protected $file;
protected $values = array();
public function __construct($file)
{
//$_GLOBALS["ran"] = true;
$this->file = $file;
$this->__set("test", "Template Working");
echo "Template Class Called.";
}
public function __set($key, $value)
{
$this->values[$key] = $value;
echo "$key set as $value<br />";
}
public function output()
{
if(!file_exists($this->file))
{
echo "ERROR: Template file not found.";
}
$output = file_get_contents($this->file);
foreach($this->values as $key => $value)
{
$find = "{".$key."}";
$output = str_replace($find, $value, $output);
}
//$_GLOBALS["ran"] = true;
return eval("?>".$output);
}
}
?>
<br />
Thing-> {test}
'if (in_array ('CLASS NAME', get_declared_classes())) {.....'는 당신이 원하는 것입니다. – Darren
@Darren 고맙습니다. 완벽하게 작동했습니다. error_reporting (0)을 추가해야했습니다. 다른 클래스를 제거하는 것은 오류라고 불리지 만, 필요한 작업을 수행합니다. 그 편지를 답으로 써서 받아 들일 수 있도록하십시오. – M4TRIX
@ 단점 유일한 문제는 페이지의 맨 위에 놓아야한다는 것이며, 무한히 반복됩니다. – M4TRIX