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


PHP ViewModel::setVariable方法代码示例

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


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

示例1: indexAction

 public function indexAction()
 {
     parent::indexAction();
     $viewmodel = new ViewModel();
     $return = array();
     if ($this->flashMessenger()->hasErrorMessages()) {
         $return['error'] = $this->flashMessenger()->getErrorMessages();
     }
     if ($this->flashMessenger()->hasSuccessMessages()) {
         $return['success'] = $this->flashMessenger()->getSuccessMessages();
     }
     $this->flashMessenger()->clearMessages();
     $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $tabid = $this->params()->fromQuery('tabid', null);
     if ($tabid) {
         $tab = $objectManager->getRepository('Application\\Entity\\Tab')->find($tabid);
         if ($tab) {
             $categories = $tab->getCategories();
             $cats = array();
             foreach ($categories as $cat) {
                 $cats[] = $cat->getId();
             }
             $viewmodel->setVariable('onlyroot', $tab->isOnlyroot());
             $viewmodel->setVariable('cats', $cats);
             $viewmodel->setVariable('tabid', $tabid);
         } else {
             $return['error'][] = "Impossible de trouver l'onglet correspondant. Contactez votre administrateur.";
         }
     } else {
         $return['error'][] = "Aucun onglet défini. Contactez votre administrateur.";
     }
     $viewmodel->setVariables(array('messages' => $return));
     return $viewmodel;
 }
开发者ID:LeCoyote,项目名称:epeires2,代码行数:34,代码来源:TabsController.php

示例2: buildView

 /**
  * Prepare view renderer
  *
  * @param array $variables
  * @param \Contentinum\Options\PageOptions $pageOptions
  * @return \Zend\View\Model\ViewModel
  */
 public function buildView($variables, $pageOptions)
 {
     $view = new ViewModel($variables);
     $msg = false;
     $msgType = false;
     if (true === $this->flashMessenger()->setNamespace('mcwork')->hasCurrentErrorMessages()) {
         $msg = $this->flashMessenger()->setNamespace('mcwork')->getErrorMessages();
         $msgType = 'error';
     } elseif (true === $this->flashMessenger()->setNamespace('mcwork')->hasCurrentSuccessMessages()) {
         $msg = $this->flashMessenger()->setNamespace('mcwork')->getSuccessMessages();
         $msgType = 'success';
     } elseif (true === $this->flashMessenger()->setNamespace('mcwork')->hasCurrentWarningMessages()) {
         $msg = $this->flashMessenger()->setNamespace('mcwork')->getWarningMessages();
         $msgType = 'warning';
     }
     $view->setVariable('messages', $msg);
     $view->setVariable('msgtype', $msgType);
     if (1 === $pageOptions->getToolbar()) {
         $view->setVariable('toolbarcontent', $this->getServiceLocator()->get('mcwork_toolbar'));
     }
     if (1 === $pageOptions->getTableedit()) {
         $view->setVariable('tableeditcontent', $this->getServiceLocator()->get('mcwork_tableedit'));
     }
     if (null !== $pageOptions->getTemplate()) {
         $view->setTemplate($pageOptions->getTemplate());
     }
     return $view;
 }
开发者ID:jochum-mediaservices,项目名称:contentinum5.5,代码行数:35,代码来源:McworkController.php

示例3: editAction

 public function editAction()
 {
     $action = $this->params('action');
     $form = new CustomVocabForm($this->getServiceLocator());
     $response = $this->api()->read('custom_vocabs', $this->params('id'));
     $vocab = $response->getContent();
     $form->setData($vocab->jsonSerialize());
     if ($this->getRequest()->isPost()) {
         $form->setData($this->params()->fromPost());
         if ($form->isValid()) {
             $formData = $form->getData();
             $response = $this->api()->update('custom_vocabs', $vocab->id(), $formData);
             if ($response->isError()) {
                 $form->setMessages($response->getErrors());
             } else {
                 $this->messenger()->addSuccess('Custom vocab updated.');
                 return $this->redirect()->toRoute('admin/custom-vocab');
             }
         } else {
             $this->messenger()->addError('There was an error during validation');
         }
     }
     $view = new ViewModel();
     $view->setVariable('form', $form);
     $view->setVariable('vocab', $vocab);
     return $view;
 }
开发者ID:jimsafley,项目名称:CustomVocab,代码行数:27,代码来源:IndexController.php

示例4: render

 /**
  * Outputs message depending on flag
  *
  * @return string
  */
 public function render()
 {
     // get messages
     $allMessages = ['danger' => array_unique(array_merge($this->flashMessenger->getErrorMessages(), $this->flashMessenger->getCurrentErrorMessages())), 'success' => array_unique(array_merge($this->flashMessenger->getSuccessMessages(), $this->flashMessenger->getCurrentSuccessMessages())), 'warning' => array_unique(array_merge($this->flashMessenger->getWarningMessages(), $this->flashMessenger->getCurrentWarningMessages())), 'info' => array_unique(array_merge($this->flashMessenger->getInfoMessages(), $this->flashMessenger->getCurrentInfoMessages())), 'default' => array_unique(array_merge($this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages()))];
     // clear messages
     $this->flashMessenger->clearMessagesFromContainer();
     $this->flashMessenger->clearCurrentMessagesFromContainer();
     // initialize output
     $output = '';
     // loop through messages
     foreach ($allMessages as $groupKey => $groupMessages) {
         foreach ($groupMessages as $message) {
             $addClass = $groupKey == 'default' ? '' : 'alert-' . $groupKey;
             // setup view model
             $viewModel = new ViewModel();
             $viewModel->setVariable('alertClass', $addClass);
             $viewModel->setVariable('alertMessage', $message);
             $viewModel->setTemplate('zf2rapid-library/widget/bootstrap-alert');
             // add rendered output
             $output .= $this->getView()->render($viewModel);
         }
     }
     // return output
     return $output . "\n";
 }
开发者ID:zfrapid,项目名称:zf2rapid-library,代码行数:30,代码来源:BootstrapFlashMessenger.php

示例5: onDispatch

 /**
  * @param MvcEvent $e
  * @return mixed|void
  */
 public function onDispatch(MvcEvent $e)
 {
     $viewModel = new ViewModel();
     $valid = $this->collageData->isValid();
     $data = $this->authenticationService->getAuthData();
     $viewModel->setVariable('validInputs', $this->collageData->getValidInput());
     $viewModel->setVariable('user', $data->user);
     if (!$valid) {
         $viewModel->setTemplate('frontend/gallery/error');
         $viewModel->setVariable('messages', $this->collageData->getMessages());
         return $e->setResult($viewModel);
     }
     $uniqueId = md5(serialize($this->collageData->getValues()));
     if ($this->sessionContainer->valuesHash != $uniqueId) {
         $collectionService = $this->collectionFactory->createCollection($this->collageData);
         $images = $collectionService->getImages($this->collageData);
     } else {
         $images = $this->sessionContainer->images;
     }
     $collageHttpPath = $this->collageService->create($images, $uniqueId, $this->collageData->getWidth(), $this->collageData->getHeight(), $this->collageData->getLimit());
     if ($collageHttpPath !== false) {
         $viewModel->setVariable('collageHttpPath', $collageHttpPath);
     }
     $viewModel->setTemplate('frontend/gallery/index');
     return $e->setResult($viewModel);
 }
开发者ID:spalax,项目名称:ua-webchalange-instagram-collage,代码行数:30,代码来源:CollageController.php

示例6: editProductAction

 public function editProductAction()
 {
     if (!$this->getAuthenticationService()->hasIdentity()) {
         $this->redirect()->toRoute('admin_login');
     }
     $request = $this->getRequest();
     $viewModel = new ViewModel();
     $product = null;
     $productId = $this->params()->fromRoute('id');
     $form = $this->getAdminCatalogService()->getCatalogProductForm();
     if (null != $productId) {
         $product = $this->getObjectManager()->find('Catalog\\Entity\\Product', $productId);
     }
     $fprg = $this->fileprg($form, $this->url()->fromRoute('admin_product_edit', ['id' => $productId]), true);
     if ($fprg instanceof \Zend\Http\PhpEnvironment\Response) {
         return $fprg;
     } elseif ($fprg === false) {
         $form->bind($product);
         $viewModel->setVariable('form', $form);
         return $viewModel;
     }
     if ($form->isValid()) {
         $product = $form->getObject();
         $this->getAdminCatalogService()->saveProduct($product);
         $viewModel->setVariable('success', true);
     } else {
         $viewModel->setVariable('success', false);
     }
     $viewModel->setVariable('form', $form);
     return $viewModel;
 }
开发者ID:iprdp,项目名称:sample-cart,代码行数:31,代码来源:CatalogProductController.php

示例7: resetAction

 public function resetAction()
 {
     $viewModel = new ViewModel();
     $this->getUserService();
     $email = $this->params()->fromPost("email", false);
     if ($email) {
         $viewModel->setTemplate("chatter/account/reset");
         $this->userService->sendPasswordEmail($email);
         $viewModel->setVariable($submitted, true);
     } else {
         $uuid = $this->params()->fromPost("uuid", false);
         $password = $this->params()->fromPost("password", false);
         if ($uuid && $password) {
             $viewModel->setTemplate("chatter/account/savedpass");
             $this->userService->resetPassword($uuid, $password);
         } else {
             $uuid = $this->params()->fromQuery("uuid", false);
             if ($uuid) {
                 $viewModel->setVariable("uuid", $uuid);
                 $viewModel->setTemplate("chatter/account/newpass");
             } else {
                 $viewModel->setTemplate("chatter/account/reset");
             }
         }
     }
     return $viewModel;
 }
开发者ID:galaco,项目名称:chatter,代码行数:27,代码来源:AccountController.php

示例8: editAction

 public function editAction()
 {
     $this->setAccess('frontend/squads/create');
     $squadID = (int) $this->params('id', null);
     $squadRepo = $this->getEntityManager()->getRepository('Frontend\\Squads\\Entity\\Squad');
     $squadEntity = $squadRepo->findOneBy(array('user' => $this->identity(), 'id' => $squadID));
     if (!$squadEntity) {
         $this->flashMessenger()->addErrorMessage('Squad not found');
         return $this->redirect()->toRoute('frontend/user/squads');
     }
     $form = new Member();
     $form->setEntityManager($this->getEntityManager());
     $form->init($squadEntity);
     if ($this->getRequest()->isPost()) {
         // zf bug workaround - deleting all members
         $postedData = (array) $this->getRequest()->getPost();
         if (!isset($postedData['members'])) {
             $postedData['members'] = array();
         }
         $form->setData($postedData);
         if ($form->isValid()) {
             $this->getEntityManager()->flush();
             $this->flashMessenger()->addSuccessMessage('Members successfully edited!');
             return $this->redirect()->refresh();
         } else {
             $form->populateValues($this->getRequest()->getPost());
         }
     }
     $viewModel = new ViewModel();
     $viewModel->setTemplate('/squads/member/edit.phtml');
     $viewModel->setVariable('form', $form);
     $viewModel->setVariable('squad', $squadEntity);
     return $viewModel;
 }
开发者ID:GlitchedMan,项目名称:armasquads,代码行数:34,代码来源:SquadMemberController.php

示例9: prepareNotFoundViewModel

 public function prepareNotFoundViewModel(MvcEvent $e)
 {
     $vars = $e->getResult();
     if ($vars instanceof Response) {
         // Already have a response as the result
         return;
     }
     $response = $e->getResponse();
     if ($response->getStatusCode() != 404) {
         // Only handle 404 responses
         return;
     }
     if (!$vars instanceof ViewModel) {
         $model = new ViewModel();
         if (is_string($vars)) {
             $model->setVariable('message', $vars);
         } else {
             $model->setVariable('message', 'Page not found.');
         }
     } else {
         $model = $vars;
         if ($model->getVariable('message') === null) {
             $model->setVariable('message', 'Page not found.');
         }
     }
     // If displaying reasons, inject the reason
     $this->injectNotFoundReason($model, $e);
     // If displaying exceptions, inject
     $this->injectException($model, $e);
     // Inject controller if we're displaying either the reason or the exception
     $this->injectController($model, $e);
     ob_clean();
     throw new \Exception($model->getVariable('message') . ' ' . $model->getVariable('reason'));
 }
开发者ID:noikiy,项目名称:laravel-UI,代码行数:34,代码来源:RouteNotFoundStrategy.php

示例10: editAction

 public function editAction()
 {
     $this->getPostService();
     $viewModel = new ViewModel();
     $postId = $this->params()->fromPost('id', false);
     $userId = $this->zfcUserAuthentication()->hasIdentity() ? $this->zfcUserAuthentication()->getIdentity()->getId() : false;
     if (!$postId) {
         $postId = $this->params()->fromQuery('id', false);
         $post = $this->postService->getPost($postId);
         if ($post['user_id'] != $userId) {
             $this->redirect()->toUrl("/forum");
         } else {
             $viewModel->setVariable('postId', $post['id']);
             $viewModel->setVariable('postContent', $post['content']);
             $viewModel->setTemplate("chatter/post/edit");
         }
     } else {
         $content = $this->params()->fromPost('message', false);
         if ($postId && $content) {
             $this->postService->updatePost($postId, $content);
         }
         $post = $this->postService->getPost($postId);
         $this->redirect()->toUrl("/forum/thread?id=" . $post['thread_id']);
     }
     return $viewModel;
 }
开发者ID:galaco,项目名称:chatter,代码行数:26,代码来源:PostController.php

示例11: deleteAction

 public function deleteAction()
 {
     $viewModel = new ViewModel();
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('admin/list_price');
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $del = $request->getPost('del', 'No');
         if ($del == 'Si') {
             $id = (int) $request->getPost('id');
             $result = $this->getListPriceTable()->delete($id);
             if (isset($result) && $result) {
                 return $this->redirect()->toRoute('admin/list_price');
             } else {
                 $viewModel->setVariable("error", true);
             }
         } else {
             return $this->redirect()->toRoute('admin/list_price');
         }
     }
     $viewModel->setVariable(array('id' => $id, 'listPrice' => $this->getListPriceTable()->get($id), 'config' => $this->config));
     return $viewModel;
 }
开发者ID:kalelc,项目名称:inventory,代码行数:25,代码来源:ListPriceController.php

示例12: paysUpdateAction

 /**
  * Update pays
  * @return ViewModel
  */
 public function paysUpdateAction()
 {
     $view = new ViewModel();
     $form = new Pays();
     $code = $this->params('code');
     if ($code) {
         $paysTable = $this->getServiceLocator()->get('pays-table');
         $paysArray = $paysTable->getPaysAdmin($code);
         if (isset($paysArray["error"])) {
             return $this->redirect()->toRoute('api_admin');
         }
         $form->bind($paysArray[0]);
         if ($this->request->isPost()) {
             $post = $this->request->getPost();
             $form->setData($post);
             if (false === $form->isValid()) {
                 return $view;
             }
             $cleanedData = $form->getData();
             $this->savePays($cleanedData);
         }
         $view->setVariable("form", $form);
         $view->setVariable("code", $code);
     }
     return $view;
 }
开发者ID:adriensy,项目名称:4a-projet-zend2,代码行数:30,代码来源:AdminController.php

示例13: processAction

 /**
  * check if user is correctly login
  *
  * @return \Zend\Http\Response |ViewModel | redirect
  */
 public function processAction()
 {
     $data = $this->params()->fromPost();
     $form = new LoginForm();
     $form->setData($data);
     $viewModel = new ViewModel(["form" => $form]);
     $viewModel->setTemplate('user/login/index');
     if ($form->isValid()) {
         $this->authService = $this->getAuth();
         $adapter = $this->authService->getAdapter();
         $adapter->setIdentityValue($data['email']);
         $adapter->setCredentialValue($data['password']);
         $authResult = $this->authService->authenticate();
         if ($authResult->isValid()) {
             $identity = $authResult->getIdentity();
             $this->authService->getStorage()->write($identity);
             //TODO move bellow  logic to specific service update last login time
             return $this->redirect()->toRoute('board');
         } else {
             $viewModel->setVariable("isLoginError", true);
         }
     } else {
         $viewModel->setVariable("isFormError", true);
     }
     return $viewModel;
 }
开发者ID:jkhaled,项目名称:bms,代码行数:31,代码来源:LoginController.php

示例14: getDebugTemplate

 public function getDebugTemplate($data, $e)
 {
     $model = new ViewModel();
     $model->setVariable('exception', $e);
     $model->setVariable('data', $data);
     $model->setTemplate('debug-template');
     return $this->_renderer->render($model);
 }
开发者ID:biialaborg,项目名称:budocu.com,代码行数:8,代码来源:EmailTemplate.php

示例15: getBody

 /**
  * @param array $data
  * @return string
  */
 public function getBody(array $data = [])
 {
     $viewContent = new ViewModel($data);
     $viewContent->setTemplate($this->template);
     $content = $this->renderer->render($viewContent);
     $this->layout->setVariable('content', $content);
     return $this->renderer->render($this->layout);
 }
开发者ID:t4web,项目名称:mail,代码行数:12,代码来源:Template.php


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