本文整理汇总了PHP中Zend\View\Model\JsonModel::setJsonpCallback方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonModel::setJsonpCallback方法的具体用法?PHP JsonModel::setJsonpCallback怎么用?PHP JsonModel::setJsonpCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\Model\JsonModel
的用法示例。
在下文中一共展示了JsonModel::setJsonpCallback方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCanSerializeWithJsonpCallback
public function testCanSerializeWithJsonpCallback()
{
$array = array('foo' => 'bar');
$model = new JsonModel($array);
$model->setJsonpCallback('callback');
$this->assertEquals('callback(' . Json::encode($array) . ');', $model->serialize());
}
示例2: getJson
public static function getJson($data, $callback = null)
{
$json = new JsonModel($data);
if ($callback != null) {
$json->setJsonpCallback($callback);
}
return $json;
}
示例3: indexAction
public function indexAction()
{
$organizationId = $this->params()->fromRoute('organizationId', 0);
try {
$jobs = $this->jobRepository->findByOrganization($organizationId);
} catch (\Exception $e) {
/** @var Response $response */
$response = $this->getResponse();
$response->setStatusCode(Response::STATUS_CODE_404);
return $response;
}
$jsonModel = new JsonModel();
$jsonModel->setVariables($this->apiJobDehydrator->dehydrateList($jobs));
$jsonModel->setJsonpCallback('yawikParseJobs');
return $jsonModel;
}
示例4: jsAction
/**
* Apresentar Configurações
*
* @return JsonModel Modelo de Visualização
*/
public function jsAction()
{
// Capturar Configurações
$configs = [];
// Inicialização
$view = new JsonModel($configs);
// Requisição
$request = $this->getRequest();
// Tipagem Correta?
if (!$request instanceof Http\PhpEnvironment\Request) {
throw new Exception('Invalid Request');
}
// Configurar Caminho Base
$view->setVariable('basePath', $this->getRequest()->getBaseUrl());
// Configurar Linguagem de Localização
$view->setVariable('locale', $this->getLocale());
// Configurar Variável
$view->setJsonpCallback('$.application.setConfigs');
// Apresentação
return $view;
}
示例5: translateAction
/**
* Translate
*
* @return JsonModel
*/
public function translateAction()
{
$model = new JsonModel();
$namespace = $this->getEvent()->getRouteMatch()->getParam('namespace', 'default');
$locale = $this->getEvent()->getRouteMatch()->getParam('locale', null);
if ($this->getRequest()->getMethod() === 'GET') {
$params = $this->getRequest()->getQuery();
if (array_key_exists('callback', $params)) {
$model->setJsonpCallback($params['callback']);
}
} else {
$params = $this->getRequest()->getPost();
}
if (!isset($params['key'])) {
$model->setVariable('error', 'No key[] given');
}
if (!is_array($params['key'])) {
$params['key'] = array($params['key']);
}
foreach ($params['key'] as $key) {
$model->setVariable($key, $this->getTranslator()->translate($key, $namespace, $locale));
}
return $model;
}
示例6: msg
/**
* 返回信息
*
* @param bool $status
* @param string $message
* @param string $jsonModel
* @return \Zend\View\Model\JsonModel multitype:unknown <boolean, unknown>
*/
public function msg($status, $message, $jsonModel = true, $jsonpCallback = null)
{
$rst = array('success' => is_bool($status) ? $status : false, 'msg' => $message);
if ($jsonModel) {
$obj = new JsonModel($rst);
if ($jsonpCallback !== null) {
$obj->setJsonpCallback($jsonpCallback);
}
return $obj;
}
return $rst;
}