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


PHP ItemInterface::getName方法代码示例

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


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

示例1: render

 public function render(ItemInterface $item, array $options = array())
 {
     $options = array_merge($this->defaultOptions, $options);
     $translator = $options['translator'];
     $itemIterator = new \Knp\Menu\Iterator\RecursiveItemIterator($item);
     $iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
     $items = [];
     foreach ($iterator as $item) {
         $translatedLabel = $translator->trans($item->getLabel());
         $id = $item->getName();
         $itemData = ['id' => strtolower($item->getName()), 'name' => $translatedLabel, 'uri' => $item->getUri()];
         $itemData['has_children'] = $item->hasChildren();
         $parentId = $item->getParent()->getName();
         if ($parentId !== $id) {
             $itemData['parent'] = strtolower($parentId);
             if (!isset($items[$parentId]['children'])) {
                 $items[$parentId]['children'] = [];
             }
             $items[$parentId]['children'][] = $itemData;
         }
         if (isset($items[$id])) {
             $items[$id] = array_merge($itemData, $items[$id]);
         } else {
             $items[$id] = $itemData;
         }
     }
     return $items;
 }
开发者ID:bgamrat,项目名称:crispy-octo-parakeet,代码行数:28,代码来源:JsonRenderer.php

示例2: render

 public function render(ItemInterface $item, array $options = array())
 {
     $options = array_merge(array('currentClass' => 'active'), $options);
     if ('root' === $item->getName()) {
         $item->setChildrenAttribute('class', trim('nav navbar-nav ' . $item->getAttribute('class')));
     }
     return parent::render($item, $options);
 }
开发者ID:nmariani,项目名称:bootstrapp-bundle,代码行数:8,代码来源:TwigRenderer.php

示例3: addCurrent

 public function addCurrent(ItemInterface $menu)
 {
     $currentRoute = $this->stack->getMasterRequest()->get('_route');
     $route = $this->menu[$menu->getName()]['route'];
     if ($currentRoute == $route) {
         $menu->setCurrent(true);
     }
 }
开发者ID:npakai,项目名称:enhavo,代码行数:8,代码来源:MenuEventListener.php

示例4: renderSpanElement

 protected function renderSpanElement(ItemInterface $item, array $options)
 {
     return sprintf('<span%s>%s</span>', $this->renderHtmlAttributes($item->getLabelAttributes()), $item->getName());
 }
开发者ID:santhapa,项目名称:ci-mag-cms,代码行数:4,代码来源:MenuRenderer.php

示例5: setContext

 /**
  * Set uri, display context to menu item
  *
  * @param  MenuItemInterface $item
  * @param  array             $routeParameters
  * @param  array             $options
  *
  * @return MenuFactoryInterface
  */
 protected function setContext(MenuItemInterface $item, array $routeParameters = array(), array $options = array())
 {
     $display = true;
     $rootItem = !$item->getName();
     $token = $this->security->getToken();
     if ($token) {
         if ($options['roles'] && !$this->security->isGranted($options['roles'])) {
             $display = false;
         }
         if ($display) {
             foreach ((array) $item->getExtra('oids') as $oidItem) {
                 if (!$this->security->isGranted($oidItem['permissions'], $oidItem['oid'])) {
                     $display = false;
                     break;
                 }
             }
         }
     }
     if ($options['route'] && !$rootItem) {
         $acceptedRouteParameters = array_intersect_key($routeParameters, $options['routeAcceptedParameters']);
         if ($options['routeRequiredParameters'] === $options['routeAcceptedParameters']) {
             $uri = $this->router->generate($options['route'], $acceptedRouteParameters, $options['routeAbsolute']);
             $item->setUri($uri);
         } else {
             $display = false;
         }
     }
     if (!$display) {
         if ($options['showNonAuthorized'] && !$token) {
             $display = true;
         }
         if ($options['showAsText']) {
             $display = true;
             $item->setUri(null);
         }
     }
     if (!$display) {
         $item->setDisplay(false);
     }
     return $this;
 }
开发者ID:paramonov,项目名称:MillwrightMenuBundle,代码行数:50,代码来源:MenuFactory.php

示例6: moveChildToPosition

    /**
     * Moves child to specified position. Rearange other children accordingly.
     *
     * @param \Knp\Menu\ItemInterface $child Child to move.
     * @param integer $position Position to move child to.
     * @return \Knp\Menu\ItemInterface
     */
    public function moveChildToPosition(ItemInterface $child, $position)
    {
        $name = $child->getName();
        $order = array_keys($this->children);

        $oldPosition = array_search($name, $order);
        unset($order[$oldPosition]);

        $order = array_values($order);

        array_splice($order, $position, 0, $name);
        $this->reorderChildren($order);

        return $this;
    }
开发者ID:naderman,项目名称:KnpMenu,代码行数:22,代码来源:MenuItem.php

示例7: toArray

 /**
  * @param ItemInterface $item
  * @param integer|null  $depth the depth until which children should be exported (null means unlimited)
  *
  * @return array
  */
 public function toArray(ItemInterface $item, $depth = null)
 {
     $array = array('name' => $item->getName(), 'label' => $item->getLabel(), 'uri' => $item->getUri(), 'attributes' => $item->getAttributes(), 'labelAttributes' => $item->getLabelAttributes(), 'linkAttributes' => $item->getLinkAttributes(), 'childrenAttributes' => $item->getChildrenAttributes(), 'extras' => $item->getExtras(), 'display' => $item->isDisplayed(), 'displayChildren' => $item->getDisplayChildren(), 'current' => $item->isCurrent());
     // export the children as well, unless explicitly disabled
     if (0 !== $depth) {
         $childDepth = null === $depth ? null : $depth - 1;
         $array['children'] = array();
         foreach ($item->getChildren() as $key => $child) {
             $array['children'][$key] = $this->toArray($child, $childDepth);
         }
     }
     return $array;
 }
开发者ID:andrewkrug,项目名称:repucaution,代码行数:19,代码来源:MenuManipulator.php


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