2017-07-17 22 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。在那里获得一些反馈也是很好的。