本文整理汇总了PHP中Zend\View\Model\JsonModel类的典型用法代码示例。如果您正苦于以下问题:PHP JsonModel类的具体用法?PHP JsonModel怎么用?PHP JsonModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JsonModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getThumbsAction
public function getThumbsAction()
{
// width of html doc
$screen_width = (int) $this->params()->fromQuery('screen_width');
//width of browser viewport
$width = (int) $this->params()->fromQuery('width');
$height = (int) $this->params()->fromQuery('height');
$direction = $this->params()->fromQuery('direction');
$galleryModel = $this->getVideosModel();
$limit = $galleryModel->getLimit($width, $height);
//$page = (int)$this->params('page');
$page = (int) $this->params()->fromQuery('page');
$offset = 0;
if ($page > 0) {
$offset = $page * $limit;
}
$cache = $this->getVideosModel()->getThumbVideosCache();
$key = $offset . "_" . $limit;
$jsonStr = $cache->getItem($key, $success);
if ($this->disableCache || !$success) {
$thumbArr = $this->getVideosMapper()->fetchThumbArr($offset, $limit);
if ($thumbArr) {
$cache->setItem($key, serialize($thumbArr));
}
} else {
$thumbArr = unserialize($jsonStr);
}
$jsonModel = new JsonModel(array("result" => $thumbArr));
$jsonModel->setTerminal(true);
return $jsonModel;
}
示例2: onInvokation
protected function onInvokation(MvcEvent $e, $error = false)
{
$viewModel = $e->getResult();
$isJsonModel = $viewModel instanceof JsonModel;
$routeMatch = $e->getRouteMatch();
if ($routeMatch && $routeMatch->getParam('forceJson', false) || $isJsonModel || "json" == $e->getRequest()->getQuery('format') || "json" == $e->getRequest()->getPost('format')) {
if (!$isJsonModel) {
$model = new JsonModel();
if ($error) {
$model->status = 'error';
$model->message = $viewModel->message;
if ($viewModel->display_exceptions) {
if (isset($viewModel->exception)) {
$model->exception = $viewModel->exception->getMessage();
}
}
} else {
$model->setVariables($viewModel->getVariables());
}
$viewModel = $model;
$e->setResult($model);
$e->setViewModel($model);
}
$viewModel->setTerminal(true);
$strategy = new \Zend\View\Strategy\JsonStrategy(new \Zend\View\Renderer\JsonRenderer());
$view = $e->getApplication()->getServiceManager()->get('ViewManager')->getView();
$view->addRenderingStrategy(array($strategy, 'selectRenderer'), 10);
$view->addResponseStrategy(array($strategy, 'injectResponse'), 10);
}
}
示例3: testCanSerializeWithJsonpCallback
public function testCanSerializeWithJsonpCallback()
{
$array = array('foo' => 'bar');
$model = new JsonModel($array);
$model->setJsonpCallback('callback');
$this->assertEquals('callback(' . Json::encode($array) . ');', $model->serialize());
}
示例4: folderPermissionsAction
public function folderPermissionsAction()
{
$jsonModel = new JsonModel();
foreach ($this->config['component'] as $component) {
if (@$component['image_path'] || @$component['video_path'] || @$component['file_path']) {
if (isset($component['image_path']) && !empty($component['image_path'])) {
if (!file_exists($component['image_path'])) {
$oldmask = umask(0);
mkdir($component['image_path'], 0777);
umask($oldmask);
$jsonModel->setVariable($component['image_path'], $component['image_path']);
}
}
if (isset($component['video_path']) && !empty($component['video_path'])) {
if (!file_exists($component['video_path'])) {
$oldmask = umask(0);
mkdir($component['video_path'], 0777);
umask($oldmask);
$jsonModel->setVariable($component['video_path'], $component['video_path']);
}
}
if (isset($component['file_path']) && !empty($component['file_path'])) {
if (!file_exists($component['file_path'])) {
$oldmask = umask(0);
mkdir($component['file_path'], 0777);
umask($oldmask);
$jsonModel->setVariable($component['file_path'], $component['file_path']);
}
}
}
}
$response = $this->getResponse();
$response->setContent(json_encode($jsonModel->getVariables()));
return $response;
}
示例5: __invoke
public function __invoke($variables = null, $options = null, $template = null)
{
$viewModel = new JsonModel($variables, $options);
if ($template) {
$viewModel->setTemplate($template);
}
return $viewModel;
}
示例6: fetchallAction
/**
* todo lay ra môn học dùng cho tags ở search
*/
public function fetchallAction()
{
/** @var \Subject\Model\SubjectMapper $subjectMapper */
$subjectMapper = $this->getServiceLocator()->get('Subject\\Model\\SubjectMapper');
$jsonModel = new JsonModel();
$jsonModel->setVariables($subjectMapper->suggest(null));
return $jsonModel;
}
示例7: getJson
public static function getJson($data, $callback = null)
{
$json = new JsonModel($data);
if ($callback != null) {
$json->setJsonpCallback($callback);
}
return $json;
}
示例8: getJsonResponse
/**
* getJsonResponse
*
* @param Result $result result
*
* @return \Zend\Stdlib\ResponseInterface
*/
public function getJsonResponse($result)
{
$view = new JsonModel();
$view->setTerminal(true);
$response = $this->getResponse();
$json = json_encode($result);
$response->setContent($json);
$response->getHeaders()->addHeaders(['Content-Type' => 'application/json']);
return $response;
}
示例9: handleRequest
/**
* Call this method from the appropriate action method
*
* @return ApiProblemResponse|JsonModel
*/
public function handleRequest()
{
$request = $this->getRequest();
if ($request->getMethod() != $request::METHOD_GET) {
return new ApiProblemResponse(new ApiProblem(405, 'Only the GET method is allowed for this URI'));
}
$model = new JsonModel([$this->property => $this->model->fetchAll()]);
$model->setTerminal(true);
return $model;
}
示例10: deleteAction
public function deleteAction()
{
$id = $this->params()->fromQuery('id');
$em = $this->getEntityManager();
$jsonModel = new JsonModel();
/** @var $res \Base\Entity\Competition */
$res = $em->getRepository('Base\\Entity\\User')->find($id);
$em->remove($res);
$em->flush();
$jsonModel->setVariable('success', true);
return $jsonModel;
}
示例11: detailsAction
/**
* Get the details of a resource
*
* @return JsonModel
*/
public function detailsAction()
{
/** @var $options \SwaggerModule\Options\ModuleOptions */
$options = $this->serviceLocator->get('SwaggerModule\\Options\\ModuleOptions');
$resourceOptions = $options->getResourceOptions() ?: array();
$resource = $this->swagger->getResource('/' . $this->params('resource', null), $resourceOptions);
if ($resource === false) {
return new JsonModel();
}
$jsonModel = new JsonModel();
return $jsonModel->setVariables($resource);
}
示例12: deleteAction
public function deleteAction()
{
$jsonModel = new JsonModel();
$id = (int) $this->params()->fromPost('id');
if ($id > 0) {
$result = $this->getNoteTable()->delete($id);
} else {
$result = false;
}
$jsonModel->setVariable("result", $result);
return $jsonModel;
}
示例13: indexAction
/**
* Home site
*
*/
public function indexAction()
{
$paginator = $this->paginator('Cv');
$jsonFormat = 'json' == $this->params()->fromQuery('format');
if ($jsonFormat) {
$viewModel = new JsonModel();
//$items = iterator_to_array($paginator);
$viewModel->setVariables(array('items' => $this->getServiceLocator()->get('builders')->get('JsonCv')->unbuildCollection($paginator->getCurrentItems()), 'count' => $paginator->getTotalItemCount()));
return $viewModel;
}
return array('resumes' => $paginator, 'sort' => $this->params()->fromQuery('sort', 'none'));
}
示例14: testAjaxAction
/**
* test ajax
*
* @return \Zend\Stdlib\ResponseInterface
*/
public function testAjaxAction()
{
if ($this->zfcUserAuthentication()->hasIdentity()) {
$name = $this->zfcUserAuthentication()->getIdentity()->getDisplayname();
} else {
$name = 'Guest';
}
$view = new ViewModel();
$view->setTemplate('blog/ajax/test.phtml')->setTerminal(true)->setVariables(array('name' => $name));
$htmlOutput = $this->getServiceLocator()->get('viewrenderer')->render($view);
$jsonModel = new JsonModel();
$jsonModel->setVariables(array('html' => $htmlOutput));
return $jsonModel;
}
示例15: suggestAction
public function suggestAction()
{
$q = $this->getRequest()->getPost('q');
$subject = new Subject();
$subject->setName($q);
$jsonModel = new JsonModel();
if (!$q) {
$jsonModel->setVariables(['code' => 1, 'data' => []]);
return $jsonModel;
}
/** @var \Subject\Model\SubjectMapper $subjectMapper */
$subjectMapper = $this->getServiceLocator()->get('Subject\\Model\\SubjectMapper');
$jsonModel->setVariables(['code' => 1, 'data' => $subjectMapper->suggest($subject)]);
return $jsonModel;
}