wscore/html
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.
wscore/html 适用场景与选型建议
wscore/html 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68 次下载、GitHub Stars 达 2, 最近一次更新时间为 2013 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wscore/html 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wscore/html 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 68
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 14
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-02-19