2017-07-17 23 views
0

我安裝SeoBundle和配置的束建立一個站點地圖(docs)。的Symfony - SeoBundle內置EMPTY站點地圖

AppKernel.php

new Sonata\SeoBundle\SonataSeoBundle(), 
new Symfony\Cmf\Bundle\CoreBundle\CmfCoreBundle(), 
new Symfony\Cmf\Bundle\SeoBundle\CmfSeoBundle(), 

全包配置(config.yml):

sonata_seo: 
    page: 
     title: Erasmus internship – Training Experience 
     metas: 
      name: 
       keywords: Erasmus Internships, Internship in Europe, International Internships, Erasmus+, Erasmus Entrepreneur, Student Internships, Internships Abroad, Student Placements 
       description: Find Internships with Training Experience: Students can find internships & employment opportunities in Europe’s platform for internships. Search paid internships and placements abroad. 
       viewport: width=device-width, initial-scale=1 
       format-detection: telephone=no 
       robots: index, follow 
      property: 
       'og:site_name': Training Experience 
       'og:title': Erasmus internship – Training Experience 
       'og:description': Find Internships with Training Experience: Students can find internships & employment opportunities in Europe’s platform for internships. Search paid internships and placements abroad." 
       'og:url': https://www.trainingexperience.org 
       'og:image': https://www.trainingexperience.org/bundles/index/images/tx-orange.png 
      http-equiv: 
       'Content-Type':   text/html; charset=utf-8 
     head: 
      'xmlns':    http://www.w3.org/1999/xhtml 
      'xmlns:og':   http://opengraphprotocol.org/schema/ 

cmf_seo: 
    title: seo.title 
    description: seo.description 
    sitemap: 
     enabled: true 
    content_listener: 
     enabled: false 

新增航線routing.yml

sitemaps: 
    prefix: /sitemaps 
    resource: "@CmfSeoBundle/Resources/config/routing/sitemap.xml" 

現在,當我訪問/sitemaps/sitemap.xml它打開,但沒有網址列出:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"></urlset> 

我可能會錯過什麼?

+0

你修好了嗎? – breq

回答

0

重要對sitemat的項目是,他們得到了一個匹配(允許,和網站地圖名)作爲內容。大多數內容沒有加載。爲此,您的內容必須實施\Symfony\Cmf\Bundle\SeoBundle\SitemapAwareInterface,這迫使您實施並填寫標誌。您可以在測試中找到一個例子:SitemapAwareContent

<?php 

/* 
* This file is part of the Symfony CMF package. 
* 
* (c) 2011-2017 Symfony CMF 
* 
* For the full copyright and license information, please view the LICENSE 
* file that was distributed with this source code. 
*/ 

namespace Symfony\Cmf\Bundle\SeoBundle\Tests\Resources\Document; 

use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; 
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface; 
use Symfony\Cmf\Bundle\SeoBundle\SitemapAwareInterface; 
use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface; 
use Symfony\Component\Routing\Route; 

/** 
* @PHPCRODM\Document(referenceable=true, translator="attribute") 
* 
* @author Maximilian Berghoff <[email protected]> 
*/ 
class SitemapAwareContent extends ContentBase implements RouteReferrersReadInterface, TranslatableInterface, SitemapAwareInterface 
{ 
    /** 
    * @var string 
    * 
    * @PHPCRODM\Locale 
    */ 
    protected $locale; 

    /** 
    * @var ArrayCollection|Route[] 
    * 
    * @PHPCRODM\Referrers(
    * referringDocument="Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route", 
    * referencedBy="content" 
    *) 
    */ 
    protected $routes; 

    /** 
    * @var bool 
    * 
    * @PHPCRODM\Field(type="boolean",property="visible_for_sitemap") 
    */ 
    private $isVisibleForSitemap; 

    /** 
    * @var string 
    * 
    * @PHPCRODM\Field(type="string",translated=true) 
    */ 
    protected $title; 

    public function __construct() 
    { 
     $this->routes = new ArrayCollection(); 
    } 

    /** 
    * @param string $sitemap 
    * 
    * @return bool 
    */ 
    public function isVisibleInSitemap($sitemap) 
    { 
     return $this->isVisibleForSitemap; 
    } 

    /** 
    * @param bool $isVisibleForSitemap 
    * 
    * @return SitemapAwareContent 
    */ 
    public function setIsVisibleForSitemap($isVisibleForSitemap) 
    { 
     $this->isVisibleForSitemap = $isVisibleForSitemap; 

     return $this; 
    } 

    /** 
    * Add a route to the collection. 
    * 
    * @param Route $route 
    */ 
    public function addRoute($route) 
    { 
     $this->routes->add($route); 
    } 

    /** 
    * Remove a route from the collection. 
    * 
    * @param Route $route 
    */ 
    public function removeRoute($route) 
    { 
     $this->routes->removeElement($route); 
    } 

    /** 
    * Get the routes that point to this content. 
    * 
    * @return Route[] Route instances that point to this content 
    */ 
    public function getRoutes() 
    { 
     return $this->routes; 
    } 

    /** 
    * @return string|bool the locale of this model or false if 
    *      translations are disabled in this project 
    */ 
    public function getLocale() 
    { 
     return $this->locale; 
    } 

    /** 
    * @param string|bool $locale the local for this model, or false if 
    *       translations are disabled in this project 
    */ 
    public function setLocale($locale) 
    { 
     $this->locale = $locale; 
    } 
} 

你還會看到實現該接口是不是唯一的任務,你必須設置學說映射也。這樣做,默認加載器將獲取文檔並查看它們(它們現在可見)。 但是你可以自己實現你自己的加載器,選舉器(另一個decission項目選擇)和guesser(填補額外的數據)。因此,您可以決定哪些內容可以在哪些(您可以有幾個)站點地圖上可見。

documentation當前僅顯示加載器,投票者和猜猜器的過程,因此我們應該爲默認可見性標誌和默認使用情況插入一些提示。所以我創建了一個issue。在那裏獲得一些反饋也是很好的。