我有4個文件。我試圖通過一個函數將我的讀取結果傳遞給另一個頁面。我的代碼如下:將變量從一個函數傳遞到另一個函數
文件actions.php
public function getAction($action, $page, Array $vars){
if(!empty($action)){
$action = strtolower($action);
$path = $page.'/'.$action.'.php';
$currentTemplate = $this->loadActionTemplate($path);
return Array($currentTemplate, $vars);
}
else{
$action = strtolower($action);
$path = $page.'/default.php';
$currentTemplate = $this->loadActionTemplate($path);
return ($currentTemplate);
}
}
文件news.php(控制器)
$file = VIEWS_PATH.strtolower($this->template) . '.php';
if (file_exists($file)){
$currentQuery = $newsModel->viewQuery($selectQuery,$returnAll);
include_once($file);
}
}
文件news.php(主視圖)
$factory = new Actions_Factory();
$factory->getAction($action, $page, $currentQuery);
文件view.php(sub View)
print_r($currentQuery);
我無法獲得$ currentQuery來打印出view.php上的mysql轉儲,但$ currentQuery在news.php上輸出的很好。我做錯了什麼,不知道它是什麼。
任何幫助將不勝感激。
由於提前
你可能文件不存在(如果(file_exists($文件)){ ) – genesis
該文件不存在,因爲它在news.php打印(主視圖)但不打印在view.php(子視圖) – CoderX