burdaforward/bf-prg-bundle

此包帮助您将PRG模式应用于您的应用程序。

安装次数: 5,199

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 12

分支: 1

公开问题: 0

类型:symfony-bundle

2.0.0 2024-07-05 10:17 UTC

This package is auto-updated.

Last update: 2024-09-05 10:44:37 UTC


README

BFPrgBundle为基于PRG模式的URL掩码提供支持。

有关此模式的更多信息,请参阅以下链接: Post/Redirect/Get

注意:此包是为在symfony应用程序中使用而构建的。

安装与设置

  1. 运行 composer require burdaforward/bf-prg-bundle 或将包下载到您的本地供应商目录

  2. 激活此包

    • 如果您已安装Symfony Flex,则应自动激活
    • 手动通过 src/Kernel.phpconfig/bundles.php
    ...
    
    class Kernel extends BaseKernel
    {
        ... 
        
        public function registerBundles()
        {
            $bundles = array(
                ...
                
                new BurdaForward\BFPrgBundle\BFPrgBundle(),
                
                ...
            );
    
            return $bundles;
        }
    
        ...
    }
  3. 将包添加到您的路由配置中,例如 config/routes.yaml

      prg:
         resource: "@BFPrgBundle/Resources/config/routing.yml"

    此routing.yml启用了必需的路由 /prg_resolve

  4. 在最后一步中,您需要将此包的基本模板包含到您的模板中。

    (最佳位置是在关闭body标签之前。)

    {% include '@BFPrg/prg_form.html.twig' %}  

用法与示例

此包提供了一个twig函数,您可以在模板中调用它。

Function name: prg_link
Function parameter:
    url: Destination URL including GET parameter
    title: Label  of the masked link. e.g. <a href="#">TITLE</a>
    options: This is an array the supports the following options.
        class: you can set the css class of the rendered element
        element: the default is "span" but if you want to render a "button", "div" or "a" you can set it with this option
        target: you can define if the link should open in the same window (default value) or in a new one 
                valid values are
                    - _self (same frame)
                    - _top (same window
                    - _blank (new window)
        only_open_tag: has to be set true or false - the result will only return the opening tag of a prg link 
                       ATTENTION: You have to close the tag by yourself.

基本示例

{{ prg_link('http://example.org?q=sample', 'Click me')|raw }}

Result: <span class="prg-link" data-submit="aHR0cDovL2V4YW1wbGUub3JnP3E9c2FtcGxl"  data-target="_self">Click me</span>

样式表示例

{{ prg_link('http://example.org?q=sample', 'Click me', {class: 'my-link'})|raw }}

Result: <span class="prg-link my-link" data-submit="aHR0cDovL2V4YW1wbGUub3JnP3E9c2FtcGxl"  data-target="_self">Click me</span>

目标示例

{{ prg_link('http://example.org?q=sample', 'Click me', {target: '_blank'})|raw }}

Result: <span class="prg-link" data-submit="aHR0cDovL2V4YW1wbGUub3JnP3E9c2FtcGxl" data-target="_blank">Click me</span>

元素示例

{{ prg_link('http://example.org?q=sample', 'Click me', {element: 'button'})|raw }}

Result: <button class="prg-link" data-submit="aHR0cDovL2V4YW1wbGUub3JnP3E9c2FtcGxl" data-target="_self">Click me</button>

仅开放标签示例

{{ prg_link('http://example.org?q=sample', 'Title will be ignored', {only_open_tag: true)|raw }}

Result: <span class="prg-link" data-submit="aHR0cDovL2V4YW1wbGUub3JnP3E9c2FtcGxl" data-target="_self">

联系

如有疑问或建议,请联系我们。