Frontend\Core\Engine\Navigation::getPageId PHP Метод

getPageId() публичный статический Метод

Get a menuId for an specified URL
public static getPageId ( string $url, string $language = null ) : integer
$url string The URL wherefore you want a pageID.
$language string The language wherefore the pageID should be retrieved, if not provided we will load the language that was provided in the URL.
Результат integer
    public static function getPageId($url, $language = null)
    {
        // redefine
        $url = trim((string) $url, '/');
        $language = $language !== null ? (string) $language : LANGUAGE;
        // get menu items array
        $keys = self::getKeys($language);
        // get key
        $key = array_search($url, $keys);
        // return 404 if we don't known a valid Id
        if ($key === false) {
            return 404;
        }
        // return the real Id
        return (int) $key;
    }

Usage Example

Пример #1
0
 /**
  * @param KernelInterface $kernel
  */
 public function __construct(KernelInterface $kernel)
 {
     parent::__construct($kernel);
     // store in reference
     $this->getContainer()->set('breadcrumb', $this);
     // get more information for the homepage
     $homeInfo = Navigation::getPageInfo(1);
     // add homepage as first item (with correct element)
     $this->addElement($homeInfo['navigation_title'], Navigation::getURL(1));
     // get other pages
     $pages = $this->URL->getPages();
     // init vars
     $items = array();
     $errorURL = Navigation::getUrl(404);
     // loop pages
     while (!empty($pages)) {
         // init vars
         $URL = implode('/', $pages);
         $menuId = Navigation::getPageId($URL);
         $pageInfo = Navigation::getPageInfo($menuId);
         // do we know something about the page
         if ($pageInfo !== false && isset($pageInfo['navigation_title'])) {
             // only add pages that aren't direct actions
             if ($pageInfo['tree_type'] != 'direct_action') {
                 // get URL
                 $pageURL = Navigation::getUrl($menuId);
                 // if this is the error-page, so we won't show an URL.
                 if ($pageURL == $errorURL) {
                     $pageURL = null;
                 }
                 // add to the items
                 $items[] = array('title' => $pageInfo['navigation_title'], 'url' => $pageURL);
             }
         }
         // remove element
         array_pop($pages);
     }
     // reverse so everything is in place
     krsort($items);
     // loop and add elements
     foreach ($items as $row) {
         $this->addElement($row['title'], $row['url']);
     }
 }
All Usage Examples Of Frontend\Core\Engine\Navigation::getPageId