本文整理汇总了PHP中Zend\View\Model\ModelInterface::serialize方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelInterface::serialize方法的具体用法?PHP ModelInterface::serialize怎么用?PHP ModelInterface::serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\Model\ModelInterface
的用法示例。
在下文中一共展示了ModelInterface::serialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Render values as XML
*
* @param string|ModelInterface $nameOrModel The script/resource process, or a view model
* @param null|array|\ArrayAccess $values Values to use during rendering
* @return string The script output.
*/
public function render($nameOrModel, $values = null)
{
if ($nameOrModel instanceof XmlModel) {
return $nameOrModel->serialize();
}
// use case 3: Both $nameOrModel and $values are populated
throw new Exception\DomainException(sprintf('%s: Do not know how to handle operation when both $nameOrModel and $values are populated', __METHOD__));
}
示例2: render
/**
* Renders values as Icalendar
*
* @param string|\Zend\View\Model\ModelInterface $oNameOrModel : the script/resource process, or a view model
* @param null|array|\ArrayAccess $aValues : values to use during rendering
*
* @throws \DomainException
* @return string The script output.
*/
public function render($oNameOrModel, $aValues = null)
{
// Use case 1: View Models
// Serialize variables in view model
if (!$oNameOrModel instanceof IcalendarModel) {
throw new \DomainException(__METHOD__ . ': Do not know how to handle operation when both $oNameOrModel and $aValues are populated');
}
return $oNameOrModel->serialize();
}
示例3: render
/**
* Renders values as JSON
*
* @todo Determine what use case exists for accepting both $nameOrModel and $values
* @param string|Model $nameOrModel The script/resource process, or a view model
* @param null|array|\ArrayAccess $values Values to use during rendering
* @throws Exception\DomainException
* @return string The script output.
*/
public function render($nameOrModel, $values = null)
{
// use case 1: View Models
// Serialize variables in view model
if ($nameOrModel instanceof Model) {
if ($nameOrModel instanceof JsonModel) {
$values = $nameOrModel->serialize();
} else {
$values = $this->recurseModel($nameOrModel);
$values = Json::encode($values);
}
if ($this->hasJsonpCallback()) {
$values = $this->jsonpCallback . '(' . $values . ');';
}
return $values;
}
// use case 2: $nameOrModel is populated, $values is not
// Serialize $nameOrModel
if (null === $values) {
if (!is_object($nameOrModel) || $nameOrModel instanceof JsonSerializable) {
$return = Json::encode($nameOrModel);
} elseif ($nameOrModel instanceof Traversable) {
$nameOrModel = ArrayUtils::iteratorToArray($nameOrModel);
$return = Json::encode($nameOrModel);
} else {
$return = Json::encode(get_object_vars($nameOrModel));
}
if ($this->hasJsonpCallback()) {
$return = $this->jsonpCallback . '(' . $return . ');';
}
return $return;
}
// use case 3: Both $nameOrModel and $values are populated
throw new Exception\DomainException(sprintf('%s: Do not know how to handle operation when both $nameOrModel and $values are populated', __METHOD__));
}
示例4: render
/**
* Renders values as XML
*
* @todo Determine what use case exists for accepting both $nameOrModel and $values
* @param string|Model $nameOrModel The script/resource process, or a view model
* @param null|array|\ArrayAccess $values Values to use during rendering
* @throws Exception\DomainException
* @return string The script output.
*/
public function render($nameOrModel, $values = null)
{
if ($nameOrModel instanceof \ShinyRest\View\Model\XmlModel) {
return $nameOrModel->serialize();
}
#echo "<pre>";
#print_r($nameOrModel);
throw new \DomainException(get_class($nameOrModel) . " is not an instance of XmlModel");
}