Passing Variables from one functiion to another
开发者_StackOverflow中文版I have 4 files. I am trying pass my fetch results through a function to another page. My code is below:
File 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);
}
}
File news.php(controller)
$file = VIEWS_PATH.strtolower($this->template) . '.php';
if (file_exists($file)){
$currentQuery = $newsModel->viewQuery($selectQuery,$returnAll);
include_once($file);
}
}
File news.php(Main view)
$factory = new Actions_Factory();
$factory->getAction($action, $page, $currentQuery);
File view.php(sub View)
print_r($currentQuery);
I can't get $currentQuery to print out the mysql dump on view.php but $currentQuery prints out fine on news.php. I am doing something wrong and can't figure out what it is.
Any help would be much appreciated.
Thanks in Advance
$factory->getAction($action, $page, $currentQuery);
print_r($currentQuery);
You set $currentQuery
to getAction()
, but this function return result if you want function affect on argument you have to use assign by reference!
Insert "&"
in $var
to assign variable by reference
public function getAction($action, $page, Array **&$vars**){
精彩评论