inwebo/seo-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

inwebo/seo-bundle

Composer 安装命令:

composer require inwebo/seo-bundle

包简介

A lightweight Symfony bundle to manage SEO metadata and breadcrumbs.

README 文档

README

GitHub Actions Workflow Status Packagist Version Packagist Downloads

A lightweight Symfony bundle to manage SEO metadata (title, description, H1) and navigational breadcrumbs with Twig-powered templating and CLI importers.

Contents

Features

  • SEO metadata service that renders title, meta description and H1 using Twig templates.
  • Breadcrumbs service that renders a breadcrumb trail using a provided Twig partial.
  • Both features read from your Doctrine entities; you control persistence in your app.
  • Twig variables come from your controller arguments and from optional shared “bags”.
  • Two console commands to import missing items from your Symfony routes.

Requirements

  • PHP >= 8.4
  • Symfony 7.3 (FrameworkBundle, Console, Routing, TwigBundle)
  • Doctrine ORM 3.x
  • Twig 3.21+

Installation

  1. Install the package via Composer
composer require inwebo/seo-bundle
  1. Symfony will auto-register the bundle (type: symfony-bundle). No manual steps needed.

Configure your entities

This bundle ships mapped superclasses you should extend to create concrete Doctrine entities in your project.

Example: App entity for breadcrumbs

<?php

namespace App\Entity\Seo;

use Doctrine\ORM\Mapping as ORM;
use Inwebo\SeoBundle\Entity\Breadcrumb as BaseBreadcrumb;

#[ORM\Entity]
#[ORM\Table(name: 'seo_breadcrumb')]
class Breadcrumb extends BaseBreadcrumb
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    protected ?int $id = null;
}

Example: App entity for metadata

<?php

namespace App\Entity\Seo;

use Doctrine\ORM\Mapping as ORM;
use Inwebo\SeoBundle\Entity\Metadata as BaseMetadata;

#[ORM\Entity]
#[ORM\Table(name: 'seo_metadata')]
class Metadata extends BaseMetadata
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    protected ?int $id = null;
}

Bundle configuration

Tell the bundle which FQCNs to use and optionally which routes to ignore for metadata resolution.

# config/packages/inwebo_seo.yaml
inwebo_seo:
  breadcrumb:
    entity: App\Entity\Seo\Breadcrumb
  metadata:
    entity: App\Entity\Seo\Metadata
    excluded_routes:      # metadata resolution is skipped when route name starts with any of these prefixes
      - _                 # useful to ignore Symfony internals (e.g. _profiler, _wdt)
      - admin_            # example: skip your back-office

Notes

  • Doctrine mapping for the bundle’s mapped superclasses is auto-prepended, so extending them is enough.
  • You decide where and how to persist data (fixtures, admin UI, CLI importers below, etc.).

Database/migrations

After creating your concrete entities, generate and run a migration in your app:

php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate

Usage in Twig

Drop these helpers into your base layout or individual templates:

<title>{{ inwebo_seo_title() }}</title>
<meta name="description" content="{{ inwebo_seo_description() }}" />
<h1>{{ inwebo_seo_h1() }}</h1>

{# Render the breadcrumb trail #}
{{ inwebo_seo_breadcrumbs() }}

Importing from routes (CLI)

The bundle provides commands that scan your router and create missing records so you can fill them later.

# Import missing breadcrumbs for known routes
php bin/console inwebo_seo:import:breadcrumbs   # alias: is:i:b

# Import missing metadata for known routes
php bin/console inwebo_seo:import:metadata     # alias: is:i:m
  • Each command prints a table of newly persisted rows or a message if nothing is needed.
  • You can safely run these commands multiple times; they only create missing items.

Route parameters and templating

  • All breadcrumb and metadata string fields (e.g., breadcrumb name/title, metadata title/description/h1) are rendered using Twig.
  • Available Twig variables include:
    • Controller arguments for the current request (by name)
    • Values stored in the corresponding Bag (see below)
  • You can reference route parameters by name in your templates. Example:
    • Breadcrumb.name: Category: {{ category.name }}
    • Breadcrumb.title: Back to {{ category.name }}
    • Metadata.title: {{ product.name }} | My Shop

Global variables with Bags

Sometimes you want to provide extra variables not present in controller arguments. Use the provided Bags.

  • MetadataBag provides variables for metadata templates
  • BreadcrumbBag provides variables for breadcrumb templates

Add values anywhere before rendering (e.g., in a listener or controller):

<?php
use Inwebo\SeoBundle\Model\MetadataBag;
use Inwebo\SeoBundle\Model\BreadcrumbBag;

MetadataBag::create()::add(['siteName' => 'Acme']);
BreadcrumbBag::create()::add(['locale' => 'en']);

Then in your templates stored in DB you can do:

  • {{ siteName }}
  • {{ locale }}

Customizing the breadcrumbs template

The breadcrumbs HTML is rendered via the template path: @InweboSeo/_breadcrumbs.html.twig

Options to customize:

  • Easiest: copy the file from vendor/inwebo/seo-bundle/templates/_breadcrumbs.html.twig into your app and add a Twig path with higher priority for the InweboSeo namespace, or override via the standard bundles override path if configured.
  • Or, keep the function and style via CSS.

Troubleshooting

  • I see an exception like " is not a valid metadata object."
    • Ensure you created and configured your concrete Metadata entity and that a row exists for the current route.
    • Check inwebo_seo.metadata.entity is set to your FQCN and that the route name matches.
  • Breadcrumbs don’t show up:
    • Ensure a Breadcrumb row exists for the current route. Use the importer to create missing ones.
    • If you need parameters, set routeParameters on the breadcrumb so URLs can be generated.
  • Metadata not applied on some routes:
    • Use excluded_routes config to skip areas like _profiler, admin_, etc.

License

GPL-3.0-or-later. See LICENSE file for details.

inwebo/seo-bundle 适用场景与选型建议

inwebo/seo-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「metadata」 「bundle」 「breadcrumbs」 「seo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 inwebo/seo-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 inwebo/seo-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 inwebo/seo-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 35
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2025-10-19