디렉토리를 검색하고 디렉토리에서 PHP 파일을 가져 오는 기능이 있습니다. 그러면 동일한 PHP 파일이 내용과 일치하고 템플릿 이름을 가져옵니다. 어떤 이상한 이유 때문에 함수에 전달 된 변수가 인식되기 시작하지 않습니다.변수가 이미 정의되어 있지만 여전히 함수 내에서 작동하지 않습니다.
변수 $이 선택되지 않습니다. 내가 시도 몇
- 함수 내부의 변수 글로벌 만들기 같은 생각 - 더미 텍스트
- 테스트를 실패 -
- 이 조건 태그 외부 더미 텍스트를 에코 실패 -
더 많은 실패 정보
변수는이 코드 줄 앞에 사용되는 경우에만 작동합니다.
0 내가 선택한 글로벌 $ 나는이 오류 메시지가Notice: Undefined variable: selected in
을받은 제거하면
$indir = array_filter($files, function($item){
이 내가
/* Scan's the theme directory and gets the PHP files which has Template named defined (Template: Your Template Name)*/
function get_theme_templates($name = "template", $noparent = true, $selected = "Works!"){
echo "<select class=\"fs12 template\" id=\"template\" name=\"".$name."\">";
if($noparent){ echo "<option value=\"-1\">No Parent</option>";}
$dir = dirname(dirname(dirname(__FILE__))) . '/system/themes/';
$files = scandir($dir);
$indir = array_filter($files, function($item){
if($item[0] !== '.'){
if(get_extension($item) == "php"){
global $dir;
$search = "Template: ";
@header('Content-Type: text/plain');
$contents = file_get_contents(dirname(dirname(dirname(__FILE__))) . '/system/themes/' . $item);
$pattern = preg_quote($search, '/');
$pattern = "/^.*$pattern.*\$/m";
if(preg_match_all($pattern, $contents, $matches)){
$template = implode("\n", $matches[0]);
$template_sanitize = array("Template:", "/* ", " */");
$template = str_replace($template_sanitize, "", $template);
$template = trim($template);
if(trim($template) == trim($selected)){
echo "<option value=\"" . $template . $selected . "\" selected=\"selected\">" . $template . "</option>";
} else {
echo "<option value=\"" . $template . $selected . "\">" . $template . "</option>";
}
}
}
}
});
echo "</select>";
}
나는 이것을 시도하고 "Notice : Undefined variable : selected" – user3140617