studiow/html 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

studiow/html

最新稳定版本:v1.0.1

Composer 安装命令:

composer require studiow/html

包简介

A helper package for generating HTML5 tags

README 文档

README

A helper package for generating HTML5 tags

Usage

Installation

The easiest way to install this package is using composer:

composer require studiow/html

Basic usage

Generating HTML tags with this package is pretty easy:

// Create the element
$link = new \Studiow\HTML\Element("a", "Documents", ["href"=>"/documents"]);

// Output
echo (string) $link;
// prints <a href="/documents">Documents</a>

Getting and setting attributes

Working with attributes is easy too:

// Create the element
$link = new \Studiow\HTML\Element("a", "Documents", ["href"=>"/documents"]);

// Set an attribute
$link->setAttribute('title', 'Go to documents');

// Get the value for an attribute
$link->getAttribute('title');  // returns  'Go to documents'
$link->getAttribute('attr_not_set');  // returns  null

// Remove an attribute
$link->removeAttribute('title');

A touch of class

Working with classes works pretty much as you'd expect:

// Create the element
$link = new \Studiow\HTML\Element("a", "Documents", ["href"=>"/documents"]);

// Add a single class
$link->addClass("button");

// Add multiple classes seperated by a space
$link->addClass("button button-documents");

// Remove a class
$link->removeClass("button");

// Check if the element has a certain class
$link->hasClass("button-documents");

Method chaining

You can go ahead and chain the methods together

$link = new Studiow\HTML\Element("a");
$link->setInnerHTML("Documents")
        ->setAttribute("href", "/documents")
        ->addClass("button")
        ->addClass("button-documents")
        ->setAttribute('title', "Go to documents");
echo (string) $link; // Outputs <a href="/documents" class="button button-documents" title="Go to documents">Documents</a>

Known Issues

Case (in)sensitve

HTML5 attributes are supposed to be case-insensitive, but here they are case-sensitive. Lowercase recommended!

Where is getChildren() etc.?

This package is by no means meant as a tool to generate large pieces of HTML. While you can use an Element as the innerHTML of another Element it will be converted to text when you do this.

If you find yourself rendering large pieces of HTML within a PHP script, you'd probably be better of using a template system.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-21