3

Let's suppose I have a Php function like this:

private function verification($isXLSFile = false) {

    if ($isXLSFile) {
        $this->parseXLSFile();
    }else {
        $parsedCSVArr = $this->getCSVarr();
        Zend_Registry::get('VMMS_ZEND_CACHE')->save($parsedCSVArr, $this->getXLSCacheName());
        Zend_Registry::get('VMMS_ZEND_CACHE')->save($isXLSFile, $this->getXLSCacheName());
    }
}

And then I call another function checking the CACHE like this:

private function process(){
    Logger::info("EnterDataMassUpload - Start Process...");
    if (($parsedCSVArr = Zend_Registry::get('VMMS_ZEND_CACHE')->load($this->getXLSCacheName())) === false) {
        $this->verification();
        return;
    }
    //if XLS file it reads the lines for each sheet.
    if ($isXLSFile == true) {
        $i=0;
        //make sure there's no duplicated row
        $parsedCSVArr = array_unique($parsedCSVArr, SORT_REGULAR);
        foreach($parsedCSVArr as $sheetIndex=>$arr){
            foreach ($arr as $k=>$line) {
                $this->processLine($line, $k);
                $i++;
            }
        }
    } else { //for a CSV file
        foreach($parsedCSVArr as $k=>$line){
            $this->processLine($line, $k);
        }
    }
    // ...

As you can see, I'm trying to save 2 variables in the same place to read it in the function process(). Do you know why my flag is not working? I mean.. can I save two variables in the same place:

 Zend_Registry::get('VMMS_ZEND_CACHE')->save($parsedCSVArr, $this->getXLSCacheName());
 Zend_Registry::get('VMMS_ZEND_CACHE')->save($isXLSFile, $this->getXLSCacheName());
4

1 回答 1

3

你为什么不把它保存在两个不同的名字下?

否则,您可以使用序列化将两个变量保存在相同的名称下。

Zend_Registry::get('VMMS_ZEND_CACHE')->save(serialize(array('parsedCSVArr' => $parsedCSVArr, 'isXLSFile' => $isXLSFile)), $this->getXLSCacheName());

然后,在 process 函数中获取缓存结果和:

$cacheResult['parsedCSVArray'];
$cacheResult['isXLSFile'];
于 2012-09-13T16:20:13.267 回答