當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。