传递在我的自定义控制器中创建的回调函数


Passing callback function created in my custom controller

我有下面的代码片段,工作得很好:

<?php
require_once(FOLDER_ROOT . "/lib/transaction/RetornoBanco.php");
require_once(FOLDER_ROOT . "/lib/transaction/RetornoFactory.php");
$fileName = 'test.txt';
function rowProcess($self, $numLn, $vrow) {
    print ($numLn . ' - ' . $vrow);
}
$test = RetornoFactory::getRetorno($fileName, 'rowProcess');
$retorno = new RetornoBanco($test);
$retorno->process();

getRetorno函数使用'rowProcess'作为处理函数。但现在我试着在我的自定义控制器(在我自己的Magento扩展,看起来像Zend控制器)。

对于我的文件(test.txt)的每一行,rowProcess运行。

但是现在,在我的控制器中,rowProcess有一个类。我的控制器:

class MY_CLASS_HERE extends Mage_Adminhtml_Controller_Action
{
    public function uploadAction()
    {   
        //just to simplify, this uploaded file exists
        $fileName = '/home/user/public_html/app/files/file.RET';
        $test = RetornoFactory::getRetorno($fileName, "rowProcess");
        $retorno = new RetornoBanco($test);
        $retorno->process();
        echo 'My Controller Here';
    }
    public function rowProcess($self, $numLn, $vrow)
    {
        print ($numLn . ' - ' . $vrow);
        //I'm creating log to prevent it is not a problem for standard output
        Mage::log($numLn . ' - ' . $vrow);
        //This function log is default in Magento and works without problems.
    }
}

我的控制器工作得很好,但现在处理程序不打印任何东西!我认为这是错误的,因为现在我的函数处理程序内部的一个类和getRetorno函数不能使用它。我该怎么做才能解决这个问题?

这样使用怎么样?你能试试吗?

    $test = RetornoFactory::getRetorno($fileName, $this->rowProcess);