双元素/后端包

CMS 帖子

安装: 136

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

公开问题: 0

类型:symfony-bundle

v1.8.0 2023-05-30 16:51 UTC

This package is auto-updated.

Last update: 2024-09-30 01:48:57 UTC


README

安装 1.composer

2.添加到 routes.yaml

post_admin:
    resource: "@TwinElementsPostBundle/Controller/Admin/"
    prefix: /admin
    type: annotation
    requirements:
        _locale: '%app_locales%'
    defaults:
        _locale: '%locale%'
        _admin_locale: '%admin_locale%'
    options: { i18n: false }

预览 URL 生成器

创建类 PostPreviewGenerator

class PostPreviewGenerator implements PostPreviewGeneratorInterface
{
    private RouterInterface $router;

    public function __construct(RouterInterface $router)
    {
        $this->router = $router;
    }

    public function generatePreviewUrl(Post $post): string
    {
        return $this->router->generate('post', [
            'id' => $post->getId(),
            'slug' => $post->getSlug()
        ]);
    }
}

service.yaml

services:
    TwinElements\PostBundle\UrlGenerator\PostPreviewGeneratorInterface:
        alias: 'App\PreviewUrlGenerator\PostPreviewGenerator'