2012-02-01 3 views
0

나는 모든 spl_autoload_registers()를 실행하는 "BaseCore"라는 클래스가 있습니다. 이 파일에 있습니다.spl_autoload_register 및 하위 클래스

class BaseCore{ 

public function __construct(){ 
    spl_autoload_register('loadClasses'); 
    spl_autoload_register('loadConfig'); 
    spl_autoload_register('loadFMAPI'); 
} 

내 두 번째 클래스 내가 BaseCore을 확장 할 때마다 새로운 클래스에, 나는/요구해야하는 BaseCore 클래스를 포함 BaseCore를 확장합니다.

그러나이 방법은 매우 쓸모 없으며 오래된 방법입니다.

내 질문에, 어떻게 require_once() 쓸 필요없이 내 자식 클래스에 BaseCore 포함 할 것이라고 생각합니다; 모든 어린이 계급에?

감사합니다.

+0

이동 spl_autoload_register ('loadClasses'); 프론트 컨트롤러 또는 초기화 스크립트 – Fivell

+0

미안 프론트 컨트롤러 또는 init 스크립트의 의미는 무엇입니까? – DarkMantis

+1

http://en.wikipedia.org/wiki/Front_Controller_pattern – Fivell

답변

2

모든 spl_autoload_register 클래스는 어떤 유형의 부트 스트랩 파일에 있어야합니다. 예를 들어 bootstrap.php를 만들고 여기에 모든 자동로드 호출을 넣으십시오. 그러면 부트 스트랩 파일을 항상 포함시켜야합니다. 예를 들어 index.php에 'bootstrap.php'가 필요합니다.

그게 전부입니다. bootstrap.php가 한 번만로드 된 다음 오토로더를 사용하여 모든 클래스를로드 할 수 있으며 필요에 따라 require 또는 require_once를 가질 필요가 없습니다.