darvinstudio/darvin-sitemap-bundle

该包为基于Symfony2的应用程序提供简单的生成网站地图的功能。

安装: 132

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

公开问题: 0

类型:symfony-bundle

5.0.0 2016-02-26 07:28 UTC

This package is auto-updated.

Last update: 2024-09-15 19:29:17 UTC


README

该包为基于Symfony2的应用程序提供简单的生成网站地图的功能。

安装

1. 将包添加到 composer.json 文件的 "required" 部分。

"require": {
    "darvinstudio/darvin-sitemap-bundle": "1.0.*"
}

2. 使用 Composer 下载包。

$ /usr/bin/env php composer.phar update darvinstudio/darvin-sitemap-bundle

3. 在 AppKernel.php 中注册包。

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Darvin\SitemapBundle\DarvinSitemapBundle(),
        // ...
    );
}

4. 从包导入路由配置到应用路由配置。

# app/config/routing.yml
darvin_sitemap:
    resource: "@DarvinSitemapBundle/Resources/config/routing.yml"
    prefix:   /

使用方法

1. 创建一个实现了 \Darvin\SitemapBundle\Url\SitemapUrlProviderInterface 接口类。

// src/AppBundle/Sitemap/TestSitemapUrlProvider.php
<?php

namespace AppBundle\Sitemap;

use Darvin\SitemapBundle\Url\SitemapUrl;
use Darvin\SitemapBundle\Url\SitemapUrlProviderInterface;

class TestSitemapUrlProvider implements SitemapUrlProviderInterface
{
    public function getSitemapUrls()
    {
        $urls = array();
        
        $urls[] = new SitemapUrl('http://example.com', new \DateTime('2016-01-01'), 'always', 0.5);

        return $urls;
    }
}

2. 将创建的类定义为服务,并使用 "darvin_sitemap.url_provider" 标签。

# app/config/services.yml
app.sitemap.url_provider.test:
    class: AppBundle\Sitemap\TestSitemapUrlProvider
    tags:
        - { name: darvin_sitemap.url_provider }

3. 将浏览器指向 http://your-domain.com/sitemap.xml 以获取您的网站地图。

配置参考

darvin_sitemap:
    cache_max_age: 3600 # Shared cache max age, 60 minutes
    # Read https://symfony.com.cn/doc/current/book/http_cache.html to know how to enable shared cache, which is highly recommended
    template:
        DarvinSitemapBundle:Sitemap:sitemap.xml.twig