承接 kikwik/page-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

kikwik/page-bundle

Composer 安装命令:

composer require kikwik/page-bundle

包简介

Manage pages for symfony 6.4+

README 文档

README

Manage pages with translations for symfony 6.4+

Installation

  1. require the bundle
#!/bin/bash
composer require kikwik/page-bundle
  1. Define the enabled_locales in config/packages/translation.yaml
framework:
  default_locale: it
  enabled_locales: ['it','en','de','fr']
  1. Optionally configure options in config/packages/kikwik_page.yaml
kikwik_page:
  admin_role: 'ROLE_ADMIN_PAGE'   # set to empty string to disable permission checker
  default_locale: '%kernel.default_locale%'
  enabled_locales: '%kernel.enabled_locales%'
  resolve_target_entities:
    page: App\Entity\Pages\Page
    page_translation: App\Entity\Pages\PageTranslation
    block: App\Entity\Pages\Block
  1. Define your entity and make them extends base classes
// src/Entity/Pages/Page.php
namespace App\Entity\Pages;

use Doctrine\ORM\Mapping as ORM;
use Kikwik\PageBundle\Entity\AbstractPage;
use Kikwik\PageBundle\Model\PageInterface;

#[ORM\Entity()]
#[ORM\Table(name: 'kw_page__page')]
class Page extends AbstractPage implements PageInterface
{
}
// src/Entity/Pages/PageTranslation.php
namespace App\Entity\Pages;

use Doctrine\ORM\Mapping as ORM;
use Kikwik\PageBundle\Entity\AbstractPageTranslation;
use Kikwik\PageBundle\Model\PageTranslationInterface;

#[ORM\Entity()]
#[ORM\Table(name: 'kw_page__page_translation')]
class PageTranslation extends AbstractPageTranslation implements PageTranslationInterface
{
}
// src/Entity/Pages/Block.php
namespace App\Entity\Pages;

use Doctrine\ORM\Mapping as ORM;
use Kikwik\PageBundle\Entity\AbstractBlock;
use Kikwik\PageBundle\Model\BlockInterface;

#[ORM\Entity()]
#[ORM\Table(name: 'kw_page__block')]
class Block extends AbstractBlock implements BlockInterface
{
}
  1. Clear your cache and update databse
symfony console cache:clear
symfony console doctrine:schema:update --force

Page admin

To activate the page admin feature add routes in config/routes/kikwik_pages.yaml:

kikwik_page_bundle_admin:
    resource: '@KikwikPageBundle/config/routes.xml'
    prefix: '/admin/page'

and create a PageFormLive component in src/Twig/Components/PageFormLive.php:

namespace App\Twig\Components;

use App\Entity\Pages\Page;
use Kikwik\PageBundle\Form\PageFormType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\DefaultActionTrait;
use Symfony\UX\LiveComponent\LiveCollectionTrait;

#[AsLiveComponent(template: '@KikwikPage/components/PageFormLive.html.twig')]
final class PageFormLive
{
    public function __construct(
        private FormFactoryInterface $formFactory,
    )
    {
    }

    use DefaultActionTrait;
    use LiveCollectionTrait;

    #[LiveProp]
    public ?Page $initialFormData = null;

    protected function instantiateForm(): FormInterface
    {
        return $this->formFactory->create(PageFormType::class, $this->initialFormData);
    }
}

Block

A block renderer must be a TwigComponent that implements Kikwik\PageBundle\Block\BlockComponentInterface You can extend BaseBlockComponent and use $this->getBlock() to retrieve the Block entity and $this->get('paramName') to get the parameter value. The buildEditForm will be used in admin to create the form that will edit parameters

namespace App\Twig\Components;

use Kikwik\PageBundle\Block\BaseBlockComponent;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormInterface;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent]
class Alert extends BaseBlockComponent
{
   
    public function buildEditForm(FormInterface $form): void
    {
        $form
            ->add('type', ChoiceType::class, [
                'choices' => ['success' => 'success', 'info' => 'info', 'warning' => 'warning', 'danger' => 'danger'],
            ])
            ->add('message',TextareaType::class, [])
        ;
    }
}
<div class="alert alert-{{ this.get('type') | default('success') }}">
    {{ this.get('message') | default('default message') }}
</div>

Child pages

Page rendering will be handled by the internal controller Kikwik\PageBundle\Controller\PageController, If a URL that partially matches a page contains extra slug parts, an event will be triggered, and you can set a Response to display a different template. If your listener does not set the response, a 404 error will be thrown.

namespace App\EventListener;

use Kikwik\PageBundle\Event\PageExtraSlugEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;

#[AsEventListener(event: PageExtraSlugEvent::NAME, method: 'onPageExtraSlug')]
class PageExtraSlugListener
{

    public function __construct(
        private Environment $twig,
        private MyCustomController $customController,
    )
    {
    }

    public function onPageExtraSlug(PageExtraSlugEvent $event)
    {
        $pageTranslation = $event->getPageTranslation();
        $extraSlug = $event->getExtraSlug();
        
        if($extraSlug == 'some string that matches')
        {
            $response = $this->customController->customAction($pageTranslation);
            $event->setResponse($response);
        }
    }
}

kikwik/page-bundle 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-16