agence-adeliom/easy-page-bundle

为 Symfony 设计的简单轻量级 CMS 套件

2.0.122 2024-05-29 09:45 UTC

README

Adeliom Quality gate

Easy Page Bundle

Easyadmin 的基本 CMS 系统

使用 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-page-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 App\Entity\EasyPage\Page;

class DashboardController extends AbstractDashboardController
{
    ...
    public function configureMenuItems(): iterable
    {
        ...
        yield MenuItem::section('easy.page.admin.menu.contents'); // (Optional)
        yield MenuItem::linkToCrud('easy.page.admin.menu.pages', 'fa fa-file-alt', Page::class);

        ...

查看页面

PageController 通过一个单一的 index() 方法处理一些查看页面的方法。

两者的 URI 都是简单的 /{slug},其中 slug 是...页面。

如果您的页面有一个父级,则 URI 如下所示:/ {parentSlug}/{slug}。

您会注意到,我们在生成的 URL 中尊重页面层次。

只要页面是父子关系,您就可以浏览复杂页面列表。

这允许您有像这样的 URL:例如,http://www.mysite.com/about/company/team/members 只会显示成员页面,但其父级有父级,依此类推,直到您达到“根”父级。对于类别也是同样的行为。

注意:这正是为什么您必须为路由使用特定规则的原因,否则您可能会遇到许多“404”错误。

根据单个页面生成路由

如果您在视图或控制器中有一个 Page 对象,您可以使用 getTree() 方法获取整个树状结构,该方法将通过所有父级导航,并返回基于分隔符参数的字符串(默认为 /,用于 URL)。

让我们通过一个这样的树状结构来举一个例子

/ - Home (root url)
├─ /welcome       - Welcome page (set as "homepage", so "Home" will be the same)
│  ├─ /welcome/our-company            - Our company
│  ├─ /welcome/our-company/financial  - Financial
│  └─ /welcome/our-company/team       - Team
└─ Contact

假设我们想要生成“团队”页面的 URL。你有一个这样的 Page 对象在你的视图/控制器中。

{# Page : "Team" #}
{{ path('easy_page_index', {"slugs": page.tree}) }}
{# Will show : /welcome/our-company/team #}

或者在控制器中

// Page : "Team"
$url = $this->generateUrl('easy_page_index', ['slugs' => $page->getTree()]);
// $url === /welcome/our-company/team

主页

主页总是第一个设置 template 属性为 homepagePage 对象。请确保只有一个元素被定义为主页,否则您可能会得到意外的结果。

设计

您有一些选项来自定义简单 CMS 的设计。

使用不同的布局

显然,默认布局没有样式。

要更改布局,只需更改 OrbitaleCmsBundle 配置以添加您自己的布局

# config/packages/easy_page.yml
easy_page:
    layouts:
        front: { resource: @App/layout.html.twig } # The Twig path to your layout

无需覆盖任何内容,您就可以轻松更改 CMS 的布局!

查看 默认布局 以了解哪些 Twig 块是必须的,以确保正确渲染页面。

高级布局配置

布局的基本配置是指定要扩展的模板。

但是,如果您查看配置参考,您将看到还有许多其他参数可以用来定义布局

布局配置原型

  • name (用于布局列表的键所用的属性)
    您布局的名称。仅为了可读性,也许可以从配置(如果需要)直接获取。
  • resource:
    用于渲染所有页面的 Twig 模板(见上文部分)
  • assets_cssassets_js
    要发送给Twig asset()函数的任何资产。CSS在stylesheets块中渲染,js在javascripts块中。
  • 主机:
    您想要布局与之匹配的精确域名。
  • 模式:
    您想要与此布局匹配的路径的正则表达式。如果您想为页面使用不同的布局,这会很有用。例如,您可以指定^/page/模式的布局,以及^/about-us/的另一个布局。如果您指定一个非常深的模式,甚至可以更改单个页面的布局!

如果您需要获取原型默认值,请参阅配置参考

⚠️ 警告! 将使用第一个匹配的布局,就像路由会做的那样,因此请确保以正确的顺序配置它们!
空值将不被考虑。

配置参考

# config/packages/easy_page.yml
easy_page:
    page_class: ~              # Required, must extend Easy Page class
    page_repository:      Adeliom\EasyPageBundle\Repository\PageRepository
    page_controller:      Adeliom\EasyPageBundle\Controller\PageController
    layouts:
        # Prototype
        name:
            name: ~             # Optional, it's automatically set from the key if it's a string
            resource: ~         # Required, must be a valid twig template
            assets_css: []      # Injected with the `asset()` twig function
            assets_js: []       # Injected with the `asset()` twig function
            assets_webpack: []  # Injected with the `encore_entry_link_tags()` and `encore_entry_script_tags()` twig functions
            pattern: ~          # Regexp
            host: ~             # Exact value
    cache:
        enabled: false
        ttl: 300

许可协议

MIT

作者

感谢

Orbitale/CmsBundle