alpixel / seobundle
SEO管理器,网站地图生成器
v2.2.1
2018-01-29 16:18 UTC
Requires
- php: >=5.3.0
- presta/sitemap-bundle: ~1.5
- sonata-project/seo-bundle: ~2.0
README
SEOBundle提供了一款能够处理自动生成元标签、根据路由指定标签以及生成网站地图的Symfony Bundle。
安装
- 安装包
composer require 'alpixel/seobundle'
- 更新AppKernel.php
new Alpixel\Bundle\SEOBundle\SEOBundle(),
- 更新数据库模式
php app/console doctrine:schema:update --force --dump-sql
元标签注解
在您的应用程序中定义元标签有两种选择
静态标签
进行中
使用占位符的动态标签
如果您需要根据实体值定义元标签,您可以在控制器中使用@MetaTag注解。
use Alpixel\Bundle\SEOBundle\Annotation\MetaTag; ... /** * @Route("/paupiette") * @MetaTag("paupiette", providerClass="My\Project\Entity\Paupiette", title="Paupiette page") */ public function displayAction() {
设置注解后,您需要运行以下命令,该命令将在数据库中注册您的新注解。
php app/console alpixel:seo:metatag:dump
然后您将在后台管理界面的“SEO”面板中看到一个新条目。您应该能够配置给定控制器的元标签模式。
受影响的实体应提供占位符。首先,它应该实现Alpixel\Bundle\SEOBundle\Entity\MetaTagPlaceholderInterface接口。然后您必须在实体中实现getPlaceholders()方法。以下是一个示例:
use Alpixel\Bundle\SEOBundle\Entity\MetaTagPlaceholderInterface; class News implements MetaTagPlaceholderInterface { public function getPlaceholders() { return array( "[news:title]" => $this->title, "[news:resume]" => substr(strip_tags($this->content), 0, 150) ); } }