-
-
Save RWOverdijk/2771090 to your computer and use it in GitHub Desktop.
Inside my controller, as long as result is Traversable or is an object with public props it works...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getTransactionDataAction() | |
{ | |
try { | |
if ($this->transaction == false || $this->transaction->getStatus() != Transaction::STATUS_COMPLETED) { | |
return $this->envelopeResult(false, sprintf(self::ERR_INCORRECT_TRANSACTION, $this->_transaction)); | |
} | |
return $this->envelopeResult(true, $this->transaction->toArray()); | |
} catch (\Exception $e) { | |
return $this->envelopeResult(false, $e->getMessage()); | |
} | |
} | |
/** | |
* Envelopes the result in an succes or error json | |
* | |
* @param type $success | |
* @param type $result | |
* @return \Zend\View\Model\JsonModel | |
*/ | |
protected function envelopeResult($success, $result) | |
{ | |
if ($success) { | |
$result = new JsonModel(new \ArrayObject(array('result' => $result))); | |
} else { | |
$result = new JsonModel(new \ArrayObject(array('error' => $result))); | |
} | |
$result->setTerminal(true); | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment