定制 qstart-soft/html-modal 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

qstart-soft/html-modal

Composer 安装命令:

composer require qstart-soft/html-modal

包简介

The Html-Modal component

关键字:

README 文档

README

The Html-Modal component provides all the tools needed to build modal windows, independent of the rest of the system.

It provides the infrastructure to separate modal processing logic from the rest of the view.

On the frontend, you can use any convenient library

Installation

$ composer require qstart-soft/html-modal

Getting Started

First you need to create a container instance of AbstractModalContainer for working with modal windows.

The container uses two types of attributes:

ModalName

It is passes a list of modal window names for which the method is used.

ModalBuilderMethod

is used to set the method in which the content is wrapped if needed. This attribute can be set in two ways

  • globally for the whole class
  • for a specific method

You can also exclude a method from wrapper processing in the following way: #[ModalBuilderMethod(ModalBuilderMethod::EMPTY_BUILDER)]

use Qstart\HtmlModal\AbstractModalContainer;
use Qstart\HtmlModal\ModalBuilderMethod;
use Qstart\HtmlModal\ModalName;

#[ModalBuilderMethod('buildModal')]
class ModalContainer extends AbstractModalContainer
{
    #[ModalName('first-modal', 'second-modal')]
    public function viewFirstModal($modalId, $modalName)
    {
        return $this->templating->render('modal-template');
    }
    
    #[ModalName('another-modal')]
    #[ModalBuilderMethod(ModalBuilderMethod::EMPTY_BUILDER)]
    public function viewAnotherModal($modalId, $modalName)
    {
        return $this->templating->render('another-modal-template');
    }
    
    public function buildModal($content)
    {
        // For example with Bootstrap Modal Component
        return sprintf(
        '<div class="modal" tabindex="-1" role="dialog">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title">Modal title</h5>
              </div>
              <div class="modal-body">%s</div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>',
        $content
        );
    }
}

Then, once you have the container with the required logic, we can set up the controller.

Let's say a request comes into a ModalController in an action named show.

We need to set up a configuration object and build a modal window. You can do this as an example:

To connect the engine to work with templates, the library is used Symfony Templating Component

use Qstart\HtmlModal\ModalBuilder;
use Qstart\HtmlModal\ModalConfig;
use Symfony\Component\Templating\PhpEngine;

class ModalController
{
    public function actionShow(PhpEngine $templating, $modalName, $modalId = null)
    {
        $config = new ModalConfig(new ModalContainer(), $templating);
        // Additional containers are connected by the following method:
        $config->setContainers([]);

        $builder = new ModalBuilder($config, $modalName, $modalId);
        $content = $builder->getContent();

        return $content;
    }
}

Wonderful!

We've separated the modal rendering logic from the rest of the view. On the frontend, you can use any convenient library

Resources

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固