2012-01-02 57 views
1

我有一些麻煩讓一個定製的痕跡: 我我layout.phtml我有:Zend框架:用麪包與部分

$container = new Zend_Navigation(); 
$this->navigation($container); 

$container->addPage(
array(
    'label'  => 'Dashboard', 
    'module'  => 'default', 
    'controller' => 'dashboard', 
    'action'  => 'index', 
    'pages'  => 
    array(
     array(
      'label'  => 'Create Order', 
      'module'  => 'default', 
      'controller' => 'createorder', 
      'action'  => 'index' 
     ), 
     array(
      'label'  => 'Query', 
      'module'  => 'default', 
      'controller' => 'query', 
      'action'  => 'index', 
      'pages' => array(
       array(
        'label'  => 'View Order', 
        'module'  => 'default', 
        'controller' => 'order', 
        'action'  => 'vieworder' 
       ) 
      ) 
     ), 
     array(
      'label'  => 'Administration', 
      'module'  => 'default', 
      'controller' => 'admin', 
      'action'  => 'index', 
      'pages'  => 
      array(
       array(
        'label'  => 'News and Announcements', 
        'module'  => 'default', 
        'controller' => 'admin', 
        'action' => 'addnews', 
        'pages' => array(
         array(
          'label'  => 'Edit News and Announcements', 
          'module'  => 'default', 
          'controller' => 'admin', 
          'action' => 'editnews' 
         ) 
        ) 
       ) 
      ) 
     ) 
    ) 
) 
); 

的下一行是:

echo $this->navigation()->breadcrumbs()->setPartial(array('BreadCrumb.phtml','default')); 

麪包屑。 phtml被稱爲很好,但我不知道如何在我的BreadCrumb.phtml中創建ul-li菜單。我如何獲得我實際上的導航? 在此先感謝您的幫助。 Andrea

回答

0

在視圖腳本中,可以通過$this->container獲取zend導航容器。該容器迭代的,所以你可以通過它用一個簡單的foreach循環行走(如foreach($this->container as $page)

4

要做到這一點,你BreadCrumb.phtml應該是這樣的:

<?php 
if (null === $this->container) { 
    $this->container = $this->breadcrumbs()->getContainer(); 
} 

// find deepest active 
if (!$active = $this->breadcrumbs()->findActive($this->container)) { 
    return ''; 
} 

$active = $active['page']; 

// put the deepest active page last in breadcrumbs 
if ($this->breadcrumbs()->getLinkLast()) { 
    $html = ' <li>' . $this->breadcrumbs()->htmlify($active) . '</li>' . PHP_EOL; 
} else { 
    $html = $active->getLabel(); 
    if ($this->breadcrumbs()->getUseTranslator() && $t = $this->breadcrumbs()->getTranslator()) { 
     $html = $t->translate($html); 
    } 
    $html = ' <li>' . $this->escape($html) . '</li>' . PHP_EOL; 
} 

// walk back to root 
while (($parent = $active->getParent()) != null) { 
    if ($parent instanceof Zend_Navigation_Page) { 
     // prepend crumb to html 
     $html = ' <li>' . $this->breadcrumbs()->htmlify($parent) . '</li>' . PHP_EOL . $html; 
    } 

    if ($parent === $this->container) { 
     // at the root of the given container 
     break; 
    } 

    $active = $parent; 
} 
echo strlen($html) ? $this->breadcrumbs()->getIndent() . '<ul id="breadcrumbs">' . PHP_EOL 
       . $html . '</ul>' . PHP_EOL : ''; 
?> 

然後你會得到這樣的事情:

<ul id="breadcrumbs"> 
    <li><a href="/home">Home</a></li> 
    <li><a href="/articles">Articles</a></li> 
    <li><a href="/shop">Shop</a></li> 
    <li>Last link</li> 
</ul> 
+0

感謝你的回覆,將進行測試很快,給你一個反饋...... – cwhisperer 2012-01-18 15:02:30

+0

沒問題,我提高了一點點我的代碼,使其更工作,如果有什麼好讓我知道! – Liyali 2012-04-04 04:53:32

+0

這是一個godd渲染麪包屑的例子@Liyali!你在哪裏找到它?這一個應該被添加到官方文檔的例子 - 目前的是「窮人」:http://framework.zend.com/manual/2.3/en/modules/zend.navigation.view.helper.breadcrumbs.html#rendering -using-a-view-script – webDEVILopers 2014-06-18 09:10:07