当前位置: 首页>>代码示例>>PHP>>正文


PHP Model\JsonModel类代码示例

本文整理汇总了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;
 }
开发者ID:nowarena,项目名称:zf2NowArena,代码行数:31,代码来源:IndexController.php

示例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);
     }
 }
开发者ID:webpants,项目名称:YAWIK,代码行数:30,代码来源:EnforceJsonResponseListener.php

示例3: testCanSerializeWithJsonpCallback

 public function testCanSerializeWithJsonpCallback()
 {
     $array = array('foo' => 'bar');
     $model = new JsonModel($array);
     $model->setJsonpCallback('callback');
     $this->assertEquals('callback(' . Json::encode($array) . ');', $model->serialize());
 }
开发者ID:benivaldo,项目名称:zf2-na-pratica,代码行数:7,代码来源:JsonModelTest.php

示例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;
 }
开发者ID:kalelc,项目名称:inventory,代码行数:35,代码来源:ConfigController.php

示例5: __invoke

 public function __invoke($variables = null, $options = null, $template = null)
 {
     $viewModel = new JsonModel($variables, $options);
     if ($template) {
         $viewModel->setTemplate($template);
     }
     return $viewModel;
 }
开发者ID:Mendim,项目名称:ep3-bs,代码行数:8,代码来源:JsonViewModel.php

示例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;
 }
开发者ID:projectHN,项目名称:mentor,代码行数:11,代码来源:SubjectController.php

示例7: getJson

 public static function getJson($data, $callback = null)
 {
     $json = new JsonModel($data);
     if ($callback != null) {
         $json->setJsonpCallback($callback);
     }
     return $json;
 }
开发者ID:rodrigogk87,项目名称:djme,代码行数:8,代码来源:ResponseUtils.php

示例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;
 }
开发者ID:wshafer,项目名称:rcmuser-api,代码行数:17,代码来源:AbstractController.php

示例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;
 }
开发者ID:erik-maas,项目名称:zf-apigility-admin,代码行数:15,代码来源:AbstractPluginManagerController.php

示例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;
 }
开发者ID:hamichen,项目名称:CMS,代码行数:12,代码来源:UserController.php

示例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);
 }
开发者ID:xl32,项目名称:SwaggerModule,代码行数:17,代码来源:DocumentationController.php

示例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;
 }
开发者ID:kalelc,项目名称:inventory,代码行数:12,代码来源:NoteController.php

示例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'));
 }
开发者ID:vfulco,项目名称:YAWIK,代码行数:16,代码来源:IndexController.php

示例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;
 }
开发者ID:hungtrinh7,项目名称:my-starter-zend-framework2,代码行数:19,代码来源:ListController.php

示例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;
 }
开发者ID:NguyenQuiDuong,项目名称:Funixtest,代码行数:15,代码来源:SubjectController.php


注:本文中的Zend\View\Model\JsonModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。