sandrokeil / html-element
Zend Framework 视图助手插件,用于使用 HTML 标签作为对象,并渲染它们。
2.0.0
2017-08-04 18:37 UTC
Requires
- php: ^7.0
- zendframework/zend-escaper: ^2.2 || ^3.0
- zendframework/zend-view: ^2.2 || ^3.0
Requires (Dev)
- container-interop/container-interop: ^1.1
- malukenho/docheader: ^0.1.4
- phpunit/phpunit: ^6.0
- sandrokeil/interop-config: ^2.1.0
- satooshi/php-coveralls: ^1.0
- squizlabs/php_codesniffer: ^3.0
Suggests
- sandrokeil/interop-config: ^2.1.0 for usage of provided factory (require PHP >= 7.1)
This package is auto-updated.
Last update: 2024-08-28 22:11:58 UTC
README
您想要将 HTML 标签作为对象使用吗?
您想要确保生成的 HTML 标签和 HTML 属性是安全的吗?
您希望在运行时生成 HTML 标签吗?
这个模块正是您需要的解决方案!
Zend Framework 视图助手插件,用于生成 HTML 标签。将 HTML 标签作为对象使用,并操作 HTML 属性和值。
- 经过充分测试。 除了单元测试和持续集成/审查,此解决方案也适用于生产使用。
- 优秀的基座。 基于 Zend Framework 和 interop-config
- 每个更改都有记录。 想要知道有什么新功能?请查看 CHANGELOG.md
- 倾听您的想法。 有一个好主意?带来经过测试的 pull request 或创建一个新的问题。请参阅 CONTRIBUTING.md
安装
此模块的安装使用 Composer。有关 Composer 文档,请参阅 getcomposer.org。
在您的 composer.json 中添加以下内容
{
"require": {
"sandrokeil/html-element": "^2.0"
}
}
请将 HtmlElement
视图助手注册到 Zend\View 插件管理器。如果您安装了 interop-config,则可以使用 Sake\HtmlElement\Service\HtmlElementFactory
工厂。
return [ 'view_helpers' => [ 'factories' => [ \Sake\HtmlElement\View\Helper\HtmlElement::class => \Sake\HtmlElement\Service\HtmlElementFactory::class, ], ], ];
文档
使用方法简单。以下是一个如何使用视图助手的示例
<?php // assume we are in a template echo $this->html('div', 'my content', array('id' => 'content', 'class' => 'box shadow')); // or $div = $this->html('div'); echo $div->setText('my content') ->setAttributes(array('id' => 'content', 'class' => 'box shadow')); // to render HTML you can use echo $div->enableHtml(true) ->setText( $this->html('p')->setText('Hello World!')->appendClass('welcome'); ); // or echo $this->html( 'div', $this->html('p')->setText('Hello World!')->appendClass('welcome'), array('id' => 'content', 'class' => 'box shadow'), true );
性能调整
HtmlElement 的默认行为是最大安全性。但如果有成千上万的 HTML 标签,可能会变慢。如果您的 HTML 属性不是来自用户输入,您可以禁用 HTML 属性的转义以提高性能。您也可以禁用文本的转义来释放这个怪兽。;-) 这只需在您的配置文件中添加以下几行即可,但请记住保持安全性。
<?php return array( 'sake_htmlelement' => array( 'view_helper' => array( 'default' => array( 'escapeHtmlAttribute' => false, 'escapeText' => false, ), ), ), // other module config stuff );