2011-07-22 72 views
0

我有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上輸出的很好。我做錯了什麼,不知道它是什麼。

任何幫助將不勝感激。

由於提前

+0

你可能文件不存在(如果(file_exists($文件)){ ) – genesis

+0

該文件不存在,因爲它在news.php打印(主視圖)但不打印在view.php(子視圖) – CoderX

回答

0
$factory->getAction($action, $page, $currentQuery); 

print_r($currentQuery); 

您設置$currentQuerygetAction(),但如果你想對你有參考使用指定的參數功能影響這個函數返回的結果!

插入"&"$var通過引用變量賦值

public function getAction($action, $page, Array **&$vars**){ 
+0

getAction調用頁面view.php。我如何獲得$ vars在view.php頁面上打印。它在news.php上打印得很好(主視圖)。 – CoderX

+0

你測試過我的解決方案嗎? –

+0

是的,我做了,但沒有奏效 – CoderX

相關問題