2017-03-08 1 views
0

내가 웹 사이트에 대한 스마티를 사용하고 있습니다,하지만 난, 템플릿 디렉토리 캐시 디렉토리 및 컴파일 디렉토리 내가 스마티을 시작할 때마다 선언과 같이해야 짜증 해요 :멋지 - 변경 캐시 디렉토리

$smarty = new Smarty(); 
$smarty->setCacheDir(__DIR__ . '/cache/smarty/'); 
$smarty->setCompileDir(__DIR__ . '/cache/smarty_c/'); 
$smarty->setTemplateDir(__DIR__ . '/templates/'); 

예를 들어, 모든 페이지에로드되는 구성 파일에 변수를 정의하는 방법이 있습니까? 한 번만 Smarty에 알려주고 모든 디렉토리에이 디렉토리가 있으므로 매번 말하지 않아도됩니까?

+0

모든 사이트가 동일한 똑똑한 인스턴스에 액세스 할 수 있습니까? 아니면 매번 새로운 스마티()를하고 있습니까? – m13r

+0

매번 Smarty를 시작합니다 (전역 변수로 사용하지 않음). –

답변

0

Smarty 클래스를 확장 한 새로운 클래스를 작성하여 다소 문제를 해결했지만 새로운 종류의 답변을 아직 열어두고 있습니다.

class MySmarty extends Smarty 
{ 
    const SMARTY_TEMPLATES = __DIR__ . '/../templates/'; 
    const SMARTY_COMPILED = __DIR__ . '/../cache/smarty_c/'; 
    const SMARTY_CACHE  = __DIR__ . '/../cache/smarty/'; 

    public function __construct() 
    { 
     $this->setTemplateDir(self::SMARTY_TEMPLATES); 
     $this->setCompileDir(self::SMARTY_COMPILED); 
     $this->setCacheDir(self::SMARTY_CACHE); 
     parent::__construct(); 
    } 
}