오토로더를 등록하는 방법과 오토로더를 작성하는 방법을 이해합니다. 이는 전혀 문제가되지 않습니다. 주요 문제는 어떻게 적 - 어떻게 같은 뭔가를 나란히 실행이 자동 로더합니까 : 당신은 자식 클래스가 밖으로 도달하는 프로젝트에 속한다는 것을 알 수 있습니다PHP로 오토로더 - 한 번에 2 개씩 실행
class project_one_folder_class extends project_two_folder_class{}
를 부모 클래스를 호출 다른 프로젝트에서 찾습니다.
프로젝트가 연결된 방법 2의 클래스는 자동 로더에서 항상 보입니다. 프로젝트의 클래스가 보이지 않는 방법.
그래서 제가 생각한 방법은 두 개의 자동 로더를 작성하고 PHP를 등록한 다음에 등록 할 것이기 때문입니다. 어떻게 PHP는 하나만 찾고 다른 하나는 보이지 않는 것 같습니다.
어떻게 해결할 수 있습니까?
편집
프로젝트 두 부모, 프로젝트 하나는 아이입니다. 이것은 What was posted on this question보다 더 확장 된 질문입니다.
더 확장하려면 내 수업이 필요합니다.
class AisisCore_Loader_AutoLoader{
protected static $_instance;
public function get_instance(){
if(null == self::$_instance){
self::$_instance = new self();
}
return self::$_instance;
}
public function reset_instance(){
self::$_instance = null;
}
public function register_auto_loader(){
spl_autoload_register(array($this, 'load_class'));
spl_autoload_register(array($this, 'load_child_class'));
}
public function load_class($class){
$path = str_replace('_', '/', $class);
if(file_exists(get_template_directory() . '/' . $path . '.php')){
require_once(get_template_directory() . '/' . $path . '.php');
}
}
public function load_child_class($class){
$path = str_replace('_', '/', $class);
if(file_exists(get_stylesheet_directory() . '/' . $path . '.php')){
require_once(get_stylesheet_directory() . '/' . $path . '.php');
}
}
}
현재이 클래스는 상위 프로젝트에있는 모든 것을로드합니다. 자식 프로젝트에서 부모 프로젝트 개체를로드합니다. 이 클래스를 사용하여 하위 객체를 찾을 수 없으면 어떻게로드 할 수 있습니까?
워드 프레스에 익숙한 즉시 말할 것이다, 그래 그 당신이 get_stylesheet_directory
을 할 때 당신은 어떻게 이제까지 get_template_directory
을 가지고 있기 때문에 -이 알면 - 그때 아이가 get_stylesheet_directory
다음 중 하나를 사용하여 개체 프로젝트로드 2 가지 자동 로더, 하나를 작성하려는 그 그래서 get_stylesheet_directory
것을 통해 부모 객체를로드 : 초과 오류와
class project_one_folder_class extends project_two_folder_class{}
작품과 부하를.
[PSR-0] (https://github.com/php-fig/fig-standards/blob/master/acc)을 살펴보십시오. epted/PSR-0.md) 표준을 준수합니다. –
자동로드 설정을위한 PHP 코드를 보여줄 수 있습니까? – Travesty3
@ Travesty3 추가 정보를 추가했습니다. – TheWebs