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


PHP MvcEvent::getViewModel方法代码示例

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


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

示例1: initAcl

 /**
  * Add the ACL of this module to the global ACL
  *
  * @param MvcEvent $e 
  * @return void
  */
 public function initAcl(MvcEvent $e)
 {
     if ($e->getViewModel()->acl == null) {
         $acl = new Acl();
     } else {
         $acl = $e->getViewModel()->acl;
     }
     $aclConfig = (include __DIR__ . '/config/module.acl.php');
     $allResources = array();
     foreach ($aclConfig['roles'] as $role) {
         if (!$acl->hasRole($role)) {
             $role = new Role($role);
             $acl->addRole($role);
         } else {
             $role = $acl->getRole($role);
         }
         if (array_key_exists($role->getRoleId(), $aclConfig['permissions'])) {
             foreach ($aclConfig['permissions'][$role->getRoleId()] as $resource) {
                 if (!$acl->hasResource($resource)) {
                     $acl->addResource(new Resource($resource));
                 }
                 $acl->allow($role, $resource);
             }
         }
     }
     $e->getViewModel()->acl = $acl;
 }
开发者ID:CPDeutschland,项目名称:zf2-api-client,代码行数:33,代码来源:Module.php

示例2: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $app = $e->getApplication();
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $sm = $app->getServiceManager();
     $list = $this->whitelist;
     $auth = $sm->get('AuthService');
     $e->getViewModel()->setVariable('hasIdentity', $auth->hasIdentity());
     if ($auth->hasIdentity()) {
         $e->getViewModel()->setVariable('currentUserId', $auth->getStorage()->read()->id);
     } else {
         $e->getViewModel()->setVariable('currentUserId', -1);
     }
     $eventManager->attach(MvcEvent::EVENT_ROUTE, function ($e) use($list, $auth) {
         $match = $e->getRouteMatch();
         // No route match, this is a 404
         if (!$match instanceof RouteMatch) {
             return;
         } else {
             // Route is whitelisted
             $name = $match->getMatchedRouteName();
             if (in_array($name, $list)) {
                 if ($auth->hasIdentity() && $name != 'login/process') {
                     $router = $e->getRouter();
                     $url = $router->assemble(array(), array('name' => 'home'));
                     $response = $e->getResponse();
                     $response->getHeaders()->addHeaderLine('Location', $url);
                     $response->setStatusCode(302);
                     return $response;
                 } else {
                     return;
                 }
             } else {
                 // User is authenticated
                 if ($auth->hasIdentity() && $name != 'auth/logout') {
                     // $id = $this->UserAuthentication()->getIdentity()->getId();
                     // var_dump(($auth->getIdentity()));
                     // exit;
                     // var_dump($name);exit;
                     return;
                 } else {
                     // Redirect to the user login page, as an example
                     $router = $e->getRouter();
                     $url = $router->assemble(array(), array('name' => 'login'));
                     $response = $e->getResponse();
                     $response->getHeaders()->addHeaderLine('Location', $url);
                     $response->setStatusCode(302);
                     return $response;
                 }
             }
         }
     }, -100);
 }
开发者ID:benjaminchazelle,项目名称:csZendApplication,代码行数:55,代码来源:Module.php

示例3: injectLayoutMenu

 public function injectLayoutMenu(MvcEvent $event)
 {
     $viewModel = $event->getViewModel();
     if ($viewModel instanceof ViewModel && $viewModel->getTemplate() == 'layout/layout') {
         $access = $event->getApplication()->getServiceManager()->get(ServiceFactory::SERVICE);
         if ($access->isAuthorized()) {
             $viewModel = new ViewModel();
             $viewModel->setTemplate('spork-tools/footer');
             $event->getViewModel()->addChild($viewModel, 'sporkToolsMenu');
         }
     }
 }
开发者ID:sporkcode,项目名称:sporktools,代码行数:12,代码来源:AccessListener.php

示例4: dispatch

 public function dispatch(MvcEvent $event)
 {
     $auth = new AuthenticationService();
     if (!$auth->hasIdentity()) {
         $router = $event->getRouteMatch();
         if (method_exists($router, 'getMatchedRouteName') && $router->getMatchedRouteName() == 'home') {
             $event->getViewModel()->setTemplate('layout/landing');
         } else {
             $event->getViewModel()->setTemplate('layout/anonymous');
         }
     }
 }
开发者ID:bix0r,项目名称:Stjornvisi,代码行数:12,代码来源:LayoutSelectListener.php

示例5: checkAcl

 public function checkAcl(MvcEvent $e)
 {
     $route = $e->getRouteMatch()->getMatchedRouteName();
     //you set your role
     $userRole = 'guest';
     if ($e->getViewModel()->acl->hasResource($route) && !$e->getViewModel()->acl->isAllowed($userRole, $route)) {
         $response = $e->getResponse();
         //location to page or what ever
         $response->getHeaders()->addHeaderLine('Location', $e->getRequest()->getBaseUrl() . '/404');
         $response->setStatusCode(404);
     }
 }
开发者ID:rravichaudhary,项目名称:zendproductcatalog,代码行数:12,代码来源:Module.php

示例6: updateLayout

 /**
  * Switch layout based on user's role
  *
  * @param MvcEvent $e
  */
 public function updateLayout(MvcEvent $e)
 {
     $params = $e->getRouteMatch()->getParams();
     if (isset($params['backend']) && $params['backend'] && Authentication::getInstance()->hasIdentity()) {
         $config = $e->getApplication()->getServiceManager()->get('config');
         $role = Authentication::getInstance()->getIdentity()->role;
         $layouts = $config['acl']['backend_layout'];
         if ($role && isset($layouts['roles'][$role])) {
             $e->getViewModel()->setTemplate($layouts['roles'][$role]);
         } else {
             $e->getViewModel()->setTemplate($layouts['default']);
         }
     }
 }
开发者ID:hoangpt,项目名称:nextcms,代码行数:19,代码来源:LayoutListener.php

示例7: collect

 /**
  * @inheritdoc
  */
 public function collect(MvcEvent $mvcEvent)
 {
     $templates = array();
     $match = $mvcEvent->getRouteMatch();
     $templates[] = $mvcEvent->getViewModel()->getTemplate();
     if ($mvcEvent->getViewModel()->hasChildren()) {
         foreach ($mvcEvent->getViewModel()->getChildren() as $child) {
             $templates[] = $child->getTemplate();
         }
     }
     if (empty($templates)) {
         $templates[] = 'N/A';
     }
     $this->data = array('templates' => $templates, 'method' => $mvcEvent->getRequest()->getMethod(), 'status' => $mvcEvent->getResponse()->getStatusCode(), 'route' => $match === null ? 'N/A' : $match->getMatchedRouteName(), 'action' => $match === null ? 'N/A' : $match->getParam('action', 'N/A'), 'controller' => $match === null ? 'N/A' : $match->getParam('controller', 'N/A'));
 }
开发者ID:lafaiDev,项目名称:suive_com,代码行数:18,代码来源:RequestCollector.php

示例8: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $e->getViewModel()->tags = $e->getApplication()->getServiceManager()->get('TagService')->getMostPopularTags();
 }
开发者ID:Nicolassouffleur,项目名称:zf2-blog,代码行数:7,代码来源:Module.php

示例9: __invoke

 public function __invoke(MvcEvent $event)
 {
     if ($event->getViewModel()->terminate()) {
         /*
          * No need for navigation when it is not rendered anyway.
          */
         return;
     }
     $services = $event->getApplication()->getServiceManager();
     $navigation = $services->get('Core/Navigation');
     $settingsMenu = $navigation->findOneBy('route', 'lang/settings');
     if ($settingsMenu->hasChildren()) {
         /*
          * We already have the subnavigation.
          */
         return;
     }
     $moduleManager = $services->get('ModuleManager');
     $configPlugin = $services->get('ControllerPluginManager')->get('config');
     $modules = $moduleManager->getLoadedModules();
     $modulesWithSettings = $configPlugin("settings", array_keys($modules));
     $routeMatch = $event->getRouteMatch();
     $router = $event->getRouter();
     $activeModule = $event->getParam('__settings_active_module', false);
     $settingsMenu->setActive((bool) $activeModule);
     foreach ($modulesWithSettings as $key => $param) {
         $page = array('label' => isset($param['navigation_label']) ? $param['navigation_label'] : ucfirst($key), 'order' => isset($param['navigation_order']) ? $param['navigation_order'] : '10', 'class' => isset($param['navigation_class']) ? $param['navigation_class'] : null, 'resource' => 'route/lang/settings', 'route' => 'lang/settings', 'router' => $router, 'action' => 'index', 'controller' => 'index', 'params' => array('lang' => 'de', 'module' => $key), 'active' => $key == $activeModule);
         if ($routeMatch instanceof RouteMatch) {
             $page['routeMatch'] = $routeMatch;
         }
         $settingsMenu->addPage($page);
     }
 }
开发者ID:vfulco,项目名称:YAWIK,代码行数:33,代码来源:InjectSubNavigationListener.php

示例10: checkAuth

 public function checkAuth(MvcEvent $e)
 {
     $sm = $e->getApplication()->getServiceManager();
     $auth = $sm->get('AuthService');
     $match = $e->getRouteMatch();
     if (!$match instanceof RouteMatch) {
         return;
     }
     $name = $match->getMatchedRouteName();
     if (in_array($name, $this->publicRoutes)) {
         return;
     }
     //Check identity
     if ($auth->hasIdentity()) {
         $viewModel = $e->getViewModel();
         $viewModel->current_user = $auth->getIdentity();
         return;
     }
     $router = $e->getRouter();
     $url = $router->assemble(array(), array('name' => 'auth'));
     $response = $e->getResponse();
     $response->getHeaders()->addHeaderLine('Location', $url);
     $response->setStatusCode(302);
     return $response;
 }
开发者ID:khinmyatkyi,项目名称:Office_Management,代码行数:25,代码来源:Module.php

示例11: render

 /**
  * Render the view
  *
  * @param  MvcEvent $e
  * @return Response
  */
 public function render(MvcEvent $e)
 {
     $result = $e->getResult();
     if ($result instanceof Response) {
         return $result;
     }
     // Martial arguments
     $request = $e->getRequest();
     $response = $e->getResponse();
     $viewModel = $e->getViewModel();
     if (!$viewModel instanceof ViewModel) {
         return;
     }
     $view = $this->view;
     $view->setRequest($request);
     $view->setResponse($response);
     try {
         $view->render($viewModel);
     } catch (\Exception $ex) {
         if ($e->getName() === MvcEvent::EVENT_RENDER_ERROR) {
             throw $ex;
         }
         $application = $e->getApplication();
         $events = $application->getEventManager();
         $e->setError(Application::ERROR_EXCEPTION)->setParam('exception', $ex);
         $events->trigger(MvcEvent::EVENT_RENDER_ERROR, $e);
     }
     return $response;
 }
开发者ID:leonardovn86,项目名称:zf2_basic2013,代码行数:35,代码来源:DefaultRenderingStrategy.php

示例12: injectIdentityModel

 /**
  * Inject identity view model into layout
  * 
  * @param MvcEvent $event
  * @throws \Exception
  */
 public function injectIdentityModel(MvcEvent $event)
 {
     $viewModel = $event->getViewModel();
     if ($viewModel->getTemplate() == 'layout/layout') {
         $servies = $event->getApplication()->getServiceManager();
         $appConfig = $servies->get('config');
         if (isset($appConfig['view_model_identity'])) {
             $config = $appConfig['view_model_identity'];
         } else {
             throw new \Exception('view_model_identity key not found in configuration');
         }
         if (!$servies->has($config['authenticationService'])) {
             throw new \Exception('Auththentication service not found');
         }
         if (!$servies->has($config['identity'])) {
             throw new \Exception('Identity not found');
         }
         $childViewModel = new IdentityViewModel(array('auth' => $servies->get($config['authenticationService']), 'identity' => $servies->get($config['identity'])));
         if (isset($config['template'])) {
             $childViewModel->setTemplate($config['template']);
         }
         if (isset($config['captureTo'])) {
             $childViewModel->setCaptureTo($config['captureTo']);
         }
         $viewModel->addChild($childViewModel);
     }
 }
开发者ID:sporkcode,项目名称:spork,代码行数:33,代码来源:ViewModelIdentity.php

示例13: onDispatch

 public function onDispatch(MvcEvent $e)
 {
     $sm = $e->getApplication()->getServiceManager();
     $categories = $sm->get('categories');
     $vm = $e->getViewModel();
     $vm->setVariable('categories', $categories);
 }
开发者ID:rafaelcostatech,项目名称:zendframework2,代码行数:7,代码来源:Module.php

示例14: layoutChange

 public function layoutChange(MvcEvent $event)
 {
     // Change By Route Defaults
     $routeMatch = $event->getRouteMatch();
     if ($routeMatch && ($layout = $routeMatch->getParam('layout', false))) {
         $event->getTarget()->layout($layout);
         return;
     }
     /** @var \Zend\Http\PhpEnvironment\Request $request */
     $request = $event->getRequest();
     $uri = $request->getServer('REQUEST_URI');
     $config = $this->getConfig($event->getParam('application')->getConfig());
     // Change Layout by URI
     foreach ($config['uri'] as $var => $value) {
         $position = strpos($var, '*');
         if ($position !== false) {
             $uri = substr($uri, 0, $position);
             $var = substr($var, 0, $position);
         }
         if ($var == $uri) {
             if (method_exists($target = $event->getTarget(), 'layout')) {
                 $target->layout($value);
             } else {
                 $event->getViewModel()->setTemplate($value);
             }
         }
     }
 }
开发者ID:marcusamatos,项目名称:jvslayout,代码行数:28,代码来源:LayoutChangeListener.php

示例15: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     // Show flashmessages in the view
     $eventManager->attach(MvcEvent::EVENT_RENDER, function ($e) {
         $flashMessenger = new FlashMessenger();
         $messages = array();
         $flashMessenger->setNamespace('success');
         if ($flashMessenger->hasMessages()) {
             $messages['success'] = $flashMessenger->getMessages();
         }
         $flashMessenger->clearMessages();
         $flashMessenger->setNamespace('warning');
         if ($flashMessenger->hasMessages()) {
             $messages['warning'] = $flashMessenger->getMessages();
         }
         $flashMessenger->clearMessages();
         $flashMessenger->setNamespace('danger');
         if ($flashMessenger->hasMessages()) {
             $messages['danger'] = $flashMessenger->getMessages();
         }
         $flashMessenger->clearMessages();
         $e->getViewModel()->setVariable('flashMessages', $messages);
     });
 }
开发者ID:AwoyoToyin,项目名称:StockInventory,代码行数:27,代码来源:Module.php


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