jlaso / sitemap-bundle
基于 https://github.com/ouardisoft/SitemapBundle 的 Symfony2 Sitemap Bundle
dev-master / 1.0.0.x-dev
2018-11-14 20:37 UTC
Requires
- php: >=5.3.2
- symfony/framework-bundle: >=2.1,<2.3-dev
- symfony/security-bundle: >=2.1,<2.3-dev
This package is auto-updated.
Last update: 2024-09-15 11:06:10 UTC
README
基于 https://github.com/ouardisoft/SitemapBundle 的 Sitemap-bundle
使用 github 安装
在你的 composer.json 文件中添加以下行
"repositories": [
...
{
"type": "git",
"url": "https://github.com/jlaso/sitemap-bundle.git"
}
...
],
"require": {
...
"jlaso/sitemap-bundle": "1.0.*@dev",
...
}
在文件 app/AppKernel.php 中添加
...
public function registerBundles() {
$bundles = array(
...
new Jlaso\SitemapBundle\JlasoSitemapBundle(),
...
}
配置
params
- path: 这是保存 sitemap 文件的位置
- entity: 使用此实体来生成我的文件
- loc: 这是一个 sitemap 标签。我们可以使用我们的路由来生成链接。
- lastmod: 使用此参数来生成 lastmod 标签
- priority: 优先级
示例
jlaso_sitemap:
path: "%kernel.root_dir%/../web/sitemap.xml"
items:
Post:
entity: AppCoreBundle:Post
loc: {route: _post, params: {post_id: id, title: slug}}
lastmod: updatedAt
priority: 0.5
; with language support
jlaso_sitemap:
path: "%kernel.root_dir%/../web/sitemap.xml"
items:
Post:
entity: AppCoreBundle:Post
loc: {route: _post_@language, params: {post_id: id, title: slug}}
lastmod: updatedAt
priority: 0.5
; OR
jlaso_sitemap:
path: "%kernel.root_dir%/../web/sitemap.xml"
items:
Post:
entity: AppCoreBundle:Post
loc: {route: _post, params: {post_id: id, title: slug_language, language: _language}}
lastmod: updatedAt
priority: 0.5
我的路由是: _post: pattern: /{post_id}/{title}/
我的数据库表 post(id, title, slug, text, createdAt, updatedAt)
如果您没有 slug 字段并且希望从标题字段生成 slug,请使用以下配置
loc: {route: _post, params: {post_id: id, {field: title, class: App\CodeBundle\Inflector, method: slug}}}
在您的控制器中
$sitemapGenerator = $this->get('sitemap.generator');
$sitemapGenerator->generate($language);
ROUTING.YML
; alone
JlasoSitemapBundle:
pattern: /sitemap.xml
defaults: { _controller: JlasoSitemapBundle:Sitemap:generate, _method:GET }
; with language support
JlasoSitemapBundle:
pattern: /sitemap_{language}.xml
defaults: { _controller: JlasoSitemapBundle:Sitemap:generate, _method:GET, language:'' }
; with entity selection for multiple sitemap generation
JlasoSitemapBundlePost:
pattern: /sitemap-post-_{language}.xml
defaults: { _controller: JlasoSitemapBundle:Sitemap:generate, _method:GET, language:'en', item:'Post' }
# the item parameter must match with one of os_sitemap.items definition in config.yml