Skip to content

Commit

Permalink
Merge remote-tracking branch 'rmartell/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDotPro committed Mar 29, 2012
2 parents 9f60857 + c640f4a commit c3ec25c
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion library/Zend/View/Model/JsonModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,32 @@ class JsonModel extends ViewModel
*/
protected $captureTo = null;

/**
* JSONP callback (if set, wraps the return in a function call)
*
* @var string
*/
protected $jsonpCallback = null;

/**
* JSON is usually terminal
*
* @var bool
*/
protected $terminate = true;

/**
* Set the JSONP callback function name
*
* @param string $callback
* @return JsonpModel
*/
public function setJsonpCallback($callback)
{
$this->jsonpCallback = $callback;
return $this;
}

/**
* Serialize to JSON
*
Expand All @@ -60,6 +79,12 @@ public function serialize()
if ($variables instanceof Traversable) {
$variables = ArrayUtils::iteratorToArray($variables);
}
return Json::encode($variables);

if(!is_null($this->jsonpCallback))
{
return $this->jsonpCallback.'('.Json::encode($variables).')';
} else {
return Json::encode($variables);
}
}
}

0 comments on commit c3ec25c

Please sign in to comment.