0
Smarty와 함께 일부 OOP를 수행하려고합니다. 예를 들어, 넣을 때PHP 함수의 Smarty
$smarty->display('header.tpl');
을 구성 함수로 사용하면 모든 것이 작동합니다. 그러나,이 코드를 함수에 넣고 함수에서 함수를 호출하면 아무 일도 일어나지 않습니다.
함수에 코드를 사용하고 함수에서 호출 할 수있는 솔루션이 있습니까?
init.php 코드 :
class init{
public function __construct(){
$smarty = new Smarty();
$smarty->setTemplateDir('templates');
$smarty->setCompileDir('templates_c');
$smarty->setCacheDir('cache');
$smarty->setConfigDir('configs');
//$smarty->testInstall();
$smarty->display('header.tpl');
$smarty->display('content.tpl');
$smarty->display('footer.tpl');
//-----------------------------------
//-----------------------------------
//check url
//-----------------------------------
//-----------------------------------
if(isset($_REQUEST['params']) && $_REQUEST['params']!=''){
$aParams = explode('/', $_REQUEST['params']);
print_r ($aParams);
if(isset($aParams[0])) $this->lang = $aParams[0];
if(isset($aParams[1])) $this->page = $aParams[1];
}
if(!$this->lang) $this->lang = 'nl';
if(!$this->page) $this->page = 'home';
//-----------------------------------
//-----------------------------------
//Functions
//-----------------------------------
//-----------------------------------
$this->buildPage();
$this->buildHeader_Footer();
}
function buildPage(){
require_once('modules/' . $this->page . '/' . $this->page . '.php');
if($this->page == 'home') new home($this->lang, $this->page, $this->action, $this->id, $this->message);
else if($this->page == 'contact') new contact($this->lang, $this->page, $this->action, $this->id, $this->message);
}
function buildHeader_Footer(){
$smarty->display('header.tpl');
$smarty->display('footer.tpl');
}
}
Index.php는 코드 : (질문 변경 후)
require('smarty/libs/Smarty.class.php');
require_once ('modules/init/init.php');
$init = new init();
나는 코드를 편집했다. 내가 제안한대로 변경하려고했지만 작동하지 않는 것 같습니다. – Axll
코드에'class' 구조가 없습니다. 또한, 내가 말한대로 : ** 참고 **'$ this'. – hek2mgl
마지막 편집 내용으로 복사하는 것을 잊어 버렸습니다. 나는이 $ – Axll