2017-07-17 5 views
0

Ich installierte SeoBundle und konfiguriert das Bündel, um eine Sitemap (docs) zu erstellen.Symfony - SeoBundle gebaut leer Sitemap

AppKernel.php:

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

Vollbündelkonfigurationen (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 

Hinzugefügt Routen routing.yml:

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

Wenn ich jetzt /sitemaps/sitemap.xml zugreifen es geöffnet wird, aber keine URLs sind aufgeführt :

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

Was könnte ich vermissen?

+0

Haben Sie es behoben? – breq

Antwort

0

Wichtig für die Elemente auf sitemat ist, dass sie einen passenden (erlaubten und Sitemap-Namen) als Inhalt haben. Meistens ist der Inhalt nicht geladen. Um dies zu tun, muss Ihr Inhalt \Symfony\Cmf\Bundle\SeoBundle\SitemapAwareInterface implementieren, was Sie zwingt ein Flag zu implementieren und zu füllen. Sie können ein Beispiel in den Tests finden: 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; 
    } 
} 

Sie auch sehen, dass die Schnittstelle implementiert, nicht die einzige Aufgabe ist, haben Sie auch die Lehre Mapping einzustellen. Wenn Sie dies tun, holt der Standardlader Sie Dokumente und sieht sie (sie sind jetzt sichtbar). Sie können jedoch Ihren eigenen Loader, Voter (ein weiteres zu wählendes Entscheidungselement) und Guesser (um zusätzliche Daten einzugeben) selbst implementieren. So können Sie entscheiden, welcher Inhalt auf welcher Sitemap sichtbar ist (Sie können mehrere haben).

Die documentation zeigt derzeit nur den Prozess für die Loader, Voter und Guessers, daher sollten wir einige Hinweise für das Standard-Sichtbarkeits-Flag und die Standardverwendung einfügen. Also habe ich einen issue erstellt. Es wäre schön, auch dort ein Feedback zu bekommen.