2011-07-22 325 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

相关问题