2011-06-21 56 views
1

我使用的是CodeIgniter,并且遇到了一个有趣的问题。我需要使用另一个函数的变量。我打算通过简单地声明全局变量(我无法)在框架中做到这一点。所以我试着从另一个内部调用一个函数(这一切都发生在控制器中)。因为显然这不能做我做了一个帮手文件与常见的功能,然后就试图加载它,但我得到这个错误:使用codeigniter调用另一个函数

Fatal error: Call to undefined method ReporteNominas::getValues() 

辅助文件是助手文件夹内,它包含此:

function getValues($getThem, $tpar, $vpiso, $tcomi, $tgas, $ttotal){ 
      $totalPares = $tpar; 
      $ventasPiso = $vpiso; 
      $totalComisiones = $tcomi; 
      $totalGastos = $tgas; 
      $totalTotal = $ttotal; 
      if($getThem){ 
       return $totalPares . "," . $ventasPiso . "," . $totalComisiones . "," . $totalGastos . "," . $totalTotal; 
      } 
     } 

,我试图把它这样做:

$this->load->helper('helper_common_functions_helper'); 
       $this->getValues(false, $query['cant'], $query['sum'], $query['com'], $query['gas'], $query['tot']); 

什么可能我在这里失去了?

回答

3

试试这个:

$this->load->helper('helper_common_functions_helper'); 

getValues(false, $query['cant'], $query['sum'], $query['com'], $query['gas'], $query['tot']); 

一个辅助(如果处理得当)只是一组函数,不是类,所以你可以把它作为一个普通函数调用。

你也应该这样做,在你的助手:

if (! function_exists('get_values')) 
{ 
    function getValues($getThem, $tpar, $vpiso, $tcomi, $tgas, $ttotal) 
    { 
    //rest of code 
    } 
} 

为了避免“重复声明函数”错误加载时不止一次

0

助手的只是功能,所以不是叫他们像一类的与$ this->你只需将它们称为正常的php函数即可。因此,改变这种

$this->getValues(false, $query['cant'], $query['sum'], $query['com'], $query['gas'],$query['tot']); 

这个

getValues(false, $query['cant'], $query['sum'], $query['com'], $query['gas'],$query['tot']); 
相关问题