我正在创建一个控制器来显示页面。我目前有这个;
$request = str_replace("/Smarty/", "", $_SERVER['REQUEST_URI']);
$params = explode("/", $request);
function FormatArr ($Arr){
$Array_Keys = array ("PageName","Username");
if (count($Arr) > 2){
trigger_error("Unexpected Params",E_USER_ERROR);
}
return array_combine($Array_Keys,$Arr);
}
$New_Params = FormatArr($params);
在 setup.php 页面上,然后在我的库上:
class testing {
protected $Smarty;
protected $fixpath;
public function __construct($Template_Name){
$this->Smarty = new Smarty;
$this->fixpath = dirname(__FILE__)."./Templates/".$Template_Name;
$this->Smarty->compile_dir=$this->fixpath."/compile";
$this->Smarty->template_dir=$this->fixpath."/html";
}
public function index(){
$this->Smarty->assign("name","test");
$this->Smarty->assign("test","../test/");
}
public function Display_Page($PageName){
$this->$PageName();
$this->Smarty->display($PageName.".html");
}
}
$Test = new testing('Testing/');
我让它成功工作,但我想动态调用页面,这些页面将在 smarty 模板上呈现正确的变量。问题是由以下原因引起的:
$this->$PageName;
我正在努力寻找成功调用必要方法的方法