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


PHP JsonModel::setVariables方法代码示例

本文整理汇总了PHP中Zend\View\Model\JsonModel::setVariables方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonModel::setVariables方法的具体用法?PHP JsonModel::setVariables怎么用?PHP JsonModel::setVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\View\Model\JsonModel的用法示例。


在下文中一共展示了JsonModel::setVariables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例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: setVariables

 /**
  * Set variables
  *
  * Overrides parent to extract variables from JsonSerializable objects.
  *
  * @param  array|Traversable|JsonSerializable|StdlibJsonSerializable $variables
  * @param  bool $overwrite
  * @return self
  */
 public function setVariables($variables, $overwrite = false)
 {
     if ($variables instanceof JsonSerializable || $variables instanceof StdlibJsonSerializable) {
         $variables = $variables->jsonSerialize();
     }
     return parent::setVariables($variables, $overwrite);
 }
开发者ID:zfcampus,项目名称:zf-content-negotiation,代码行数:16,代码来源:JsonModel.php

示例4: 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

示例5: onRender

 public function onRender(MvcEvent $e)
 {
     if ($e->getResponse()->isOk()) {
         return;
     }
     $httpCode = $e->getResponse()->getStatusCode();
     $sm = $e->getApplication()->getServiceManager();
     $viewModel = $e->getViewModel();
     $exception = $viewModel->getVariable('exception');
     $model = new JsonModel();
     if ($exception) {
         $model->setVariables(['errorCode' => $exception->getCode, 'errorMessage' => $exception->getMessage()]);
     } else {
         $model->setVariables(['errorCode' => $httpCode, 'errorMessage' => 'error has been trigger']);
     }
     $e->setResult($model);
     $e->setViewModel($model);
     $e->getResponse()->setStatusCode($httpCode);
 }
开发者ID:jkhaled,项目名称:bms,代码行数:19,代码来源:ApiProblemListener.php

示例6: 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

示例7: 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

示例8: 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

示例9: deleteAction

 public function deleteAction()
 {
     $jsonModel = new JsonModel();
     $id = trim($this->getRequest()->getPost('id'));
     if (!$id) {
         $jsonModel->setVariables(['code' => 0, 'messages' => ['Dữ liệu không hợp lệ']]);
         return $jsonModel;
     }
     $role = new \System\Model\Role();
     $role->setId($id);
     $roleMapper = $this->getServiceLocator()->get('\\System\\Model\\RoleMapper');
     if (!$roleMapper->get($role)) {
         $jsonModel->setVariables(['code' => 0, 'messages' => ['Không tìm thấy role']]);
         return $jsonModel;
     }
     if ($roleMapper->isRoleUsed($role)) {
         $jsonModel->setVariables(['code' => 0, 'messages' => ['Quyền đang được sử dụng, không thể xóa']]);
         return $jsonModel;
     }
     $roleMapper->delete($role);
     $jsonModel->setVariable('code', 1);
     return $jsonModel;
 }
开发者ID:projectHN,项目名称:mentor,代码行数:23,代码来源:RoleController.php

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

示例11: suggestionAction

 /**
  * @uses autocomplete
  */
 public function suggestionAction()
 {
     /* @var $request \Zend\Http\Request */
     $request = $this->getRequest();
     $jsonModel = new JsonModel();
     if (!($q = urldecode(trim($request->getQuery('q'))))) {
         return $jsonModel;
     }
     $p = new \Product\Model\Store();
     $p->setServiceLocator($this->getServiceLocator());
     $data = ['searchOptions' => $p->searchOptions()];
     $limit = trim($request->getQuery('limit'));
     $p->addOption('limit', $limit > 0 ? $limit : 20);
     /* @var $baseStoreMapper \Product\Model\BaseStoreMapper */
     $baseStoreMapper = $this->getServiceLocator()->get('Product\\Model\\BaseStoreMapper');
     $products = $baseStoreMapper->search($p);
     if (is_array($products) && count($products)) {
         $cIds = [];
         foreach ($products as $p) {
             /* @var $p \Product\Model\Store */
             $p->setIsBaseProduct(true);
             $data['products'][] = $p->toStd();
             if ($p->getBaseCategoryId()) {
                 $cIds[$p->getBaseCategoryId()] = $p->getBaseCategoryId();
             }
         }
         if ($request->getQuery('showMore') && $request->getQuery('showMore') == 'category') {
             /* @var $baseCategoryMapper \Product\Model\BaseCategoryMapper */
             $baseCategoryMapper = $this->getServiceLocator()->get('Product\\Model\\BaseCategoryMapper');
             $baseCategory = new \Product\Model\BaseCategory();
             $baseCategory->setChilds($cIds);
             $baseCategory->addOption('limit', 5);
             $categories = $baseCategoryMapper->search($baseCategory);
             if (count($categories)) {
                 foreach ($categories as $c) {
                     /* @var \Product\Model\BaseCategory $c*/
                     $data['categories'][] = $c->toStd();
                 }
             }
         }
     }
     $jsonModel->setVariables($data);
     return $jsonModel;
 }
开发者ID:NguyenQuiDuong,项目名称:Funixtest,代码行数:47,代码来源:SearchsController.php

示例12: create

 public function create($data)
 {
     //echo exec('echo '.serialize($_POST).' > /home/khaled/Desktop/file.txt');
     error_log("You messed up!", 3, BASE_PATH . "/../data/log/my-errors.log");
     $file = $this->params()->fromFiles();
     $filename = $this->uploadImage($file);
     $position = new Position();
     $position->setLatitude($data['latitude']);
     $position->setLongitude($data['longitude']);
     $position->setComment($data['comment']);
     $position->setStatus($data['status']);
     $isAccident = isset($data['isAccident']) ? 1 : 0;
     $position->setIsAccident($isAccident);
     $position->setImage($filename);
     $position->setCreatedDate(time());
     $this->getEntityManager()->persist($position);
     $this->em->flush();
     $model = new JsonModel();
     $model->setVariables($data);
     return $model;
 }
开发者ID:jkhaled,项目名称:itaBackend,代码行数:21,代码来源:NewPositionController.php

示例13: indexAction

 public function indexAction()
 {
     $result = ['result' => false, 'message' => ''];
     $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $login = new LoginInputFilter();
         $this->loginForm->setInputFilter($login->getInputFilter());
         $this->loginForm->setData($request->getPost());
         if ($this->loginForm->isValid()) {
             $result = ['result' => true, 'message' => 'Ajax request success'];
         } else {
             $result = ['result' => false, 'message' => $this->loginForm->getMessages()];
         }
     }
     if (!$viewModel instanceof JsonModel && $request->isXmlHttpRequest()) {
         $viewModel = new JsonModel();
     }
     $viewModel->setVariables(['form' => $this->loginForm, 'data' => $result]);
     return $viewModel;
 }
开发者ID:sitrunlab,项目名称:learnzf2,代码行数:21,代码来源:IndexController.php

示例14: handleError

 public function handleError(MvcEvent $e)
 {
     if ($e->getError() == Application::ERROR_ROUTER_NO_MATCH) {
         return;
     }
     if ($e->getError() == Application::ERROR_EXCEPTION) {
         $translator = $e->getApplication()->getServiceManager()->get('translator');
         $exception = $e->getParam('exception');
         if ($exception instanceof BusinessException) {
             // translate
             $status = intval($exception->getCode());
             $messsage = $translator->translate($exception->getMessage());
         } else {
             $status = 999;
             if (isset($_SERVER['APPLICATION_ENV']) && $_SERVER['APPLICATION_ENV'] == 'development') {
                 $messsage = $exception->getMessage();
             } else {
                 $messsage = '对不起, 系统出错了...';
             }
         }
         /* @var $request \Zend\Http\Request */
         $request = $e->getRequest();
         $response = $e->getResponse();
         if ($request->isXmlHttpRequest()) {
             // change status code from 500 to 200
             $response->setStatusCode(200);
             $response->getHeaders()->addHeaders(array('Content-type' => 'application/json; charset=utf8'));
             $json = new JsonModel();
             $json->setVariables(array('status' => $status, 'message' => $messsage, 'content' => array()));
             $json->setTerminal(false);
             $e->setViewModel($json);
             // mute other default exception handler
             $e->setError(false);
         }
     }
 }
开发者ID:zhangyuxiao,项目名称:qoros,代码行数:36,代码来源:Module.php

示例15: indexAction

 public function indexAction()
 {
     // we need to init EACH factory to ensure it gets initialized into the statusmanager.
     $factoryList = $this->getServiceLocator()->get('Config')['service_manager']['factories'];
     foreach ($factoryList as $key => $value) {
         $noLoad = false;
         $blacklist = array('ZF', 'AcMailer', 'AssetManager', 'SlmQueue', 'StatusAwareManager', 'doctrine');
         foreach ($blacklist as $blKey => $blacklistItem) {
             if (strpos(strtolower($key), strtolower($blacklistItem)) !== false) {
                 $noLoad = true;
                 break;
             }
         }
         if ($noLoad == false) {
             // echo "Loading " . $key . "\n";
             try {
                 $factory = $this->getServiceLocator()->get($key);
                 if ($factory instanceof StatusInterface) {
                     $status = $factory->getServiceStatusAsArr();
                 }
             } catch (\Exception $e) {
                 //echo $e->getMessage();
                 //die();
             }
         }
     }
     //die();
     /**
      *
      * @var $statusAwareManager StatusManager
      */
     $statusAwareManager = $this->getServiceLocator()->get('StatusAwareManager');
     $viewModel = new JsonModel();
     $viewModel->setVariables($statusAwareManager->getStatus());
     return $viewModel;
 }
开发者ID:jackdpeterson,项目名称:status-aware,代码行数:36,代码来源:StatusController.php


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