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

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

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

wscore/html

最新稳定版本:1.1.0

Composer 安装命令:

composer require wscore/html

包简介

Html tag generator classes.

README 文档

README

Html tag generation class for PHP.

Installation

$ composer require wscore/html

Sample Codes

Basic HTML

use WScore\Html\Html class to create an HTML object, as;

use WScore\Html\Html;

$html = Html::create('tagName')
            ->set('attribute', 'value')
            ->setContents('content');
echo (string) $html;

should output HTML like,

<tagName attribute="value">content</tagName>

You can set, add, remove, reset, attributes.

There are some magic methods as well.

$html = Html::a('sample link')       // magic method to create a new tag and contents
            ->href('check.php')    // magic method to set href attribute
            ->target('_blank');

HTML Form

use WScore\Html\Form class to create a HTML form object, as;

echo Form::open('check.php');
echo Form::input('checkbox', 'keep', 'alive')->class('form-element');
echo Form::close(); 

should create something like:

<form action="check.php" method="post">
<input type="checkbox" name="keep" id="keep" value="alive" class="form-element">
</form>

Some Complex Case

To create a nested html code,

echo Html::create('ul')
            ->class('form-list')
            ->setContents(
                Form::input('text', 'name')->placeholder('name here...'),
                Form::input('radio', 'yes', 'here')
            );

should result in following html code.

<ul class="form-list">
<input type="text" name="name" id="name" placeholder="name here...">
<input type="radio" name="yes" id="yes" value="here">
</ul>

Choices (radio, checkbox, and select)

User Form::choices method to generate choices, such as radio buttons, checkboxes, and drop down selects.

For radio buttons;

echo Form::choices('test', [
    'val1' => 'label1', 
    'val2' => 'label2'], 
    'val2);

for checkboxes;

echo Form::choices('test', [
    'val1' => 'label1', 
    'val2' => 'label2'], 
    'val2)
    ->multiple();

and for drop-down selects;

echo Form::choices('test', [
    'val1' => 'label1', 
    'val2' => 'label2'], 
    'val2)
    ->expand(false);

Demo

To see WScore.Html working in the demo,

$ git clone https://github.com/asaokamei/WScore.Html
$ cd WScore.Html
$ composer install
$ cd demo
$ php -S 127.0.0.1:8000

and browse the last URL.

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-02-19