agence-adeliom/easy-redirect-bundle

为EasyAdmin的Symfony重定向Bundle


README

Adeliom Quality gate

Easy Redirect Bundle

此Bundle添加了重定向和404错误的实体。

对于重定向,拦截404错误并查找请求的路径。如果找到匹配项,则将其重定向到找到的重定向的目标。同时更新计数和最后访问日期。还有一个重定向表单类型和验证。

404错误也可以记录。每个404错误都是数据库中的一个单独记录。存储路径、完整URL、时间戳和引用者。将每个错误存储为单独的记录允许查看时间统计并查看所有引用者URL。当创建或更新重定向时,匹配其路径的404记录将被删除。

版本

使用Symfony Flex安装

添加我们的recipes端点

{
  "extra": {
    "symfony": {
      "endpoint": [
        "https://api.github.com/repos/agence-adeliom/symfony-recipes/contents/index.json?ref=flex/main",
        ...
        "flex://defaults"
      ],
      "allow-contrib": true
    }
  }
}

使用composer安装

composer require agence-adeliom/easy-redirect-bundle

设置数据库

使用doctrine迁移

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

不使用

php bin/console doctrine:schema:update --force

文档

在Easyadmin仪表板中管理重定向

转到您的仪表板控制器,例如: src/Controller/Admin/DashboardController.php

<?php

namespace App\Controller\Admin;

...
use Adeliom\EasyRedirectBundle\Admin\EasyRedirectTrait;

class DashboardController extends AbstractDashboardController
{
    ...
    use EasyRedirectTrait;

    ...
    public function configureMenuItems(): iterable
    {
        ...
        yield from $this->configRedirectEntry();

        ...

配置

# config/packages/easy_redirect.yaml
easy_redirect:
    redirect_class:     ~ # Required and must be an instance of "Adeliom\EasyRedirectBundle\Entity\Redirect"
    not_found_class:    ~ # Required and must be an instance of "Adeliom\EasyRedirectBundle\Entity\NotFound"
    model_manager_name: ~ # If a custom model manager is used by default its 'default'

    # When enabled, when a redirect is updated or created, the NotFound entites with a matching path are removed.
    remove_not_founds: true

许可

MIT

作者

感谢

kbond/ZenstruckRedirectBundle