项目作者: sandrokeil

项目描述 :
Zend Framework view helper plugin to use html tags like objects and to render them.
高级语言: PHP
项目地址: git://github.com/sandrokeil/HtmlElement.git
创建时间: 2014-04-09T20:32:49Z
项目社区:https://github.com/sandrokeil/HtmlElement

开源协议:Other

下载


HtmlElement view helper for Zend Framework

You want HTML tags as objects?

You want surefire generated HTML tags and HTML attributes?

You want to generate HTML tags on the fly?

This module comes to the rescue!

Build Status
Scrutinizer Code Quality
Coverage Status
HHVM Status
SensioLabsInsight
Latest Stable Version
Dependency Status
Total Downloads
License

Zend Framework view helper plugin for generating HTML tags. Use HTML tags as objects and manipulate HTML attributes and values.

  • Well tested. Besides unit tests and continuous integration/inspection this solution is also ready for production use.
  • Great foundations. Based on Zend Framework and interop-config
  • Every change is tracked. Want to know whats new? Take a look at CHANGELOG.md
  • Listen to your ideas. Have a great idea? Bring your tested pull request or open a new issue. See CONTRIBUTING.md

Installation

Installation of this module uses Composer. For Composer documentation, please refer to
getcomposer.org.

Put the following into your composer.json

  1. {
  2. "require": {
  3. "sandrokeil/html-element": "^2.0"
  4. }
  5. }

Please register the HtmlElement view helper to your Zend\View plugin manager.
You can use the Sake\HtmlElement\Service\HtmlElementFactory factory if you install interop-config.

  1. return [
  2. 'view_helpers' => [
  3. 'factories' => [
  4. \Sake\HtmlElement\View\Helper\HtmlElement::class => \Sake\HtmlElement\Service\HtmlElementFactory::class,
  5. ],
  6. ],
  7. ];

Documentation

The usage is easy. Here is an example how to use the view helper

  1. <?php
  2. // assume we are in a template
  3. echo $this->html('div', 'my content', array('id' => 'content', 'class' => 'box shadow'));
  4. // or
  5. $div = $this->html('div');
  6. echo $div->setText('my content')
  7. ->setAttributes(array('id' => 'content', 'class' => 'box shadow'));
  8. // to render HTML you can use
  9. echo $div->enableHtml(true)
  10. ->setText(
  11. $this->html('p')->setText('Hello World!')->appendClass('welcome');
  12. );
  13. // or
  14. echo $this->html(
  15. 'div',
  16. $this->html('p')->setText('Hello World!')->appendClass('welcome'),
  17. array('id' => 'content', 'class' => 'box shadow'),
  18. true
  19. );

Performance tweaks

The default behaviour of HtmlElement is maximum security. But if you have thousands of HTML tags it could be slow.
If your HTML attributes are not from user input, you can disable escaping of HTML attributes to increase performance.
You can also disable escaping of text to unleash the beast. ;-) This is simply done by adding the following lines to
your config file, but keep security in mind.

  1. <?php
  2. return array(
  3. 'sake_htmlelement' => array(
  4. 'view_helper' => array(
  5. 'default' => array(
  6. 'escapeHtmlAttribute' => false,
  7. 'escapeText' => false,
  8. ),
  9. ),
  10. ),
  11. // other module config stuff
  12. );