我有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