firestorm23/seobundle

SEO 管理器,网站地图生成器

安装: 13

依赖: 0

建议者: 0

安全: 0

星级: 0

关注者: 1

分支: 1

类型:symfony-bundle

v2.0.3 2016-06-15 14:20 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:42:09 UTC


README

SEOBundle 提供了一个能够处理自动生成元标签、按路由特定标签和网站地图的 Symfony Bundle。

安装

  1. 安装包
composer require 'alpixel/seobundle'
  1. 更新 AppKernel.php
new Alpixel\Bundle\SEOBundle\SEOBundle(),
  1. 更新数据库模式
php app/console doctrine:schema:update --force --dump-sql

元标签注解

在您的应用程序中定义元标签有 2 种选项

静态标签

工作正在进行中

带有占位符的动态标签

如果您有需要根据实体值定义的元标签,您可以在控制器中使用 @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)
        );
    }
}