如何使用zend Framework 1制作站点地图

时间:2018-11-02 13:19:16

标签: php zend-framework sitemap

我想为使用zf1编码的网站创建站点地图,但是对此我一无所知。

我在Google上读到我需要一个控制器,一个视图和一个路由,但是我发现它适用于zf2,并且不起作用。

有人做这个吗?

1 个答案:

答案 0 :(得分:2)

您应该在Controller Action中使用Zend_Navigation类和navigation sitemap视图帮助程序,如下所示:

public function sitemapAction()
{
  $this->_helper->layout->disableLayout();
  $this->_helper->viewRenderer->setNoRender(true);
  $items = array(
    array(
      'title' => 'Title 1',
      'label' => 'Label 1',
      'uri' => 'https://www.example.com/page1',
      'order' => 1,
      'type' => 'uri',
      'changefreq' => 'weekly',
    ),
    array(
      'title' => 'Title 2',
      'label' => 'Label 2',
      'uri' => 'https://www.example.com/page2',
      'order' => 2,
      'type' => 'uri',
      'changefreq' => 'weekly',
    )
  );
  $nav = new Zend_Navigation($items);
  $sitemapOutput = $this->view->navigation($nav)->sitemap();

  $this->_response->setHeader('Content-Type', 'text/xml; charset=utf-8')->setBody($sitemapOutput);
}