php Zend-View-Model-JsonModel类(方法)实例源码

下面列出了php Zend-View-Model-JsonModel 类(方法)源码代码实例,从而了解它的用法。

作者:nowaren    项目:zf2NowAren   
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;
 }

作者:webpant    项目:YAWI   
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);
     }
 }

作者:benivald    项目:zf2-na-pratic   
public function testCanSerializeWithJsonpCallback()
 {
     $array = array('foo' => 'bar');
     $model = new JsonModel($array);
     $model->setJsonpCallback('callback');
     $this->assertEquals('callback(' . Json::encode($array) . ');', $model->serialize());
 }

作者:kalel    项目:inventor   
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;
 }

作者:Mendi    项目:ep3-b   
public function __invoke($variables = null, $options = null, $template = null)
 {
     $viewModel = new JsonModel($variables, $options);
     if ($template) {
         $viewModel->setTemplate($template);
     }
     return $viewModel;
 }

作者:projectH    项目:mento   
/**
  * 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;
 }

作者:rodrigogk8    项目:djm   
public static function getJson($data, $callback = null)
 {
     $json = new JsonModel($data);
     if ($callback != null) {
         $json->setJsonpCallback($callback);
     }
     return $json;
 }

作者:wshafe    项目:rcmuser-ap   
/**
  * 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;
 }

作者:erik-maa    项目:zf-apigility-admi   
/**
  * 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;
 }

作者:hamiche    项目:CM   
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;
 }

作者:xl3    项目:SwaggerModul   
/**
  * 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);
 }

作者:kalel    项目:inventor   
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;
 }

作者:vfulc    项目:YAWI   
/**
  * 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'));
 }

作者:hungtrinh    项目:my-starter-zend-framework   
/**
  * 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;
 }

作者:NguyenQuiDuon    项目:Funixtes   
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;
 }

作者:ingzep    项目:BaseProyec   
public function loginAction()
 {
     $this->authService = new AuthenticationService();
     $request = (array) Json::decode($this->getRequest()->getContent());
     if ($this->getRequest()->isPost()) {
         $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter');
         $login = new Login($request, $dbAdapter);
         if ($login->ValidFilter($request)) {
             $login->Auth($dbAdapter);
         }
         $result = new JsonModel(array('message' => $login->getMessage(), 'code' => $login->getCode()));
         echo $result->serialize();
         exit;
     }
 }

作者:phpr    项目:zf-smartcru   
/**
  * @param HttpRequest $request
  *
  * @return \Zend\View\Model\ViewModel
  */
 public function build(HttpRequest $request, SmartServiceResult $result, $action)
 {
     $viewModel = null;
     if ($request->isXmlHttpRequest()) {
         $viewModel = new JsonModel();
         $viewModel->setTerminal(true);
     } else {
         $viewModel = new \Zend\View\Model\ViewModel();
         $viewModel->setVariable('entity', $result->getEntity());
         $viewModel->setVariable('form', $result->getForm());
         $viewModel->setVariable('list', $result->getList());
         $viewModel->setTemplate(sprintf($this->getTemplate(), $action));
     }
     return $viewModel;
 }

作者:CPDeutschlan    项目:zf2-api-clien   
/**
  * Method executed when the render event is triggered
  *
  * @param MvcEvent $e 
  * @return void
  */
 public static function onRender(MvcEvent $e)
 {
     if ($e->getRequest() instanceof \Zend\Console\Request || $e->getResponse()->isOk() || $e->getResponse()->getStatusCode() == Response::STATUS_CODE_401) {
         return;
     }
     $httpCode = $e->getResponse()->getStatusCode();
     $sm = $e->getApplication()->getServiceManager();
     $viewModel = $e->getResult();
     $exception = $viewModel->getVariable('exception');
     $model = new JsonModel(array('errorCode' => !empty($exception) ? $exception->getCode() : $httpCode, 'errorMsg' => !empty($exception) ? $exception->getMessage() : NULL));
     $model->setTerminal(true);
     $e->setResult($model);
     $e->setViewModel($model);
     $e->getResponse()->setStatusCode($httpCode);
 }

作者:utrenkne    项目:YAWI   
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;
 }

作者:adaca    项目:3agest-prototyp   
public function validFormAction()
 {
     $jsonModel = new JsonModel();
     $formData = $this->params()->fromPost();
     $formManager = $this->getServiceLocator()->get('formElementManager');
     $form = $formManager->get('addressForm');
     $form->setData($formData);
     $result = $form->isValid();
     $messages = [];
     if (!$result) {
         $messages = $form->getMessages();
     }
     $jsonModel->setVariable('jsonData', ['isValid' => $result, 'messages' => $messages]);
     $this->getResponse()->getHeaders()->addHeaderLine('content-type', 'application/json');
     return $jsonModel;
 }


问题


面经


文章

微信
公众号

扫码关注公众号