burdaforward / bf-prg-bundle
此包帮助您将PRG模式应用于您的应用程序。
2.0.0
2024-07-05 10:17 UTC
Requires
- php: ^8.1
- symfony/framework-bundle: ^5.4 || ^6.4
- symfony/yaml: ^5.4 || ^6.4
- twig/twig: ^2.15 || ^3.0
Requires (Dev)
- roave/security-advisories: dev-latest
README
BFPrgBundle为基于PRG模式的URL掩码提供支持。
有关此模式的更多信息,请参阅以下链接: Post/Redirect/Get
注意:此包是为在symfony应用程序中使用而构建的。
安装与设置
-
运行
composer require burdaforward/bf-prg-bundle
或将包下载到您的本地供应商目录 -
激活此包
- 如果您已安装Symfony Flex,则应自动激活
- 手动通过
src/Kernel.php
或config/bundles.php
... class Kernel extends BaseKernel { ... public function registerBundles() { $bundles = array( ... new BurdaForward\BFPrgBundle\BFPrgBundle(), ... ); return $bundles; } ... }
-
将包添加到您的路由配置中,例如
config/routes.yaml
prg: resource: "@BFPrgBundle/Resources/config/routing.yml"
此routing.yml启用了必需的路由
/prg_resolve
。 -
在最后一步中,您需要将此包的基本模板包含到您的模板中。
(最佳位置是在关闭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">
联系
如有疑问或建议,请联系我们。