20/08
2013
Html tag generator classes.
Html tag generation class for PHP., (*1)
$ composer require wscore/html
use WScore\Html\Html
class to create an HTML object, as;, (*2)
use WScore\Html\Html; $html = Html::create('tagName') ->set('attribute', 'value') ->setContents('content'); echo (string) $html;
should output HTML like,, (*3)
<tagName attribute="value">content</tagName>
You can set
, add
, remove
, reset
, attributes., (*4)
There are some magic methods as well., (*5)
$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');
use WScore\Html\Form
class to create a HTML form object, as;, (*6)
echo Form::open('check.php'); echo Form::input('checkbox', 'keep', 'alive')->class('form-element'); echo Form::close();
should create something like:, (*7)
<form action="check.php" method="post"> <input type="checkbox" name="keep" id="keep" value="alive" class="form-element"> </form>
To create a nested html code,, (*8)
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., (*9)
<ul class="form-list"> <input type="text" name="name" id="name" placeholder="name here..."> <input type="radio" name="yes" id="yes" value="here"> </ul>
User Form::choices
method to generate choices, such as radio buttons, checkboxes, and drop down selects., (*10)
For radio buttons;, (*11)
echo Form::choices('test', [ 'val1' => 'label1', 'val2' => 'label2'], 'val2);
for checkboxes;, (*12)
echo Form::choices('test', [ 'val1' => 'label1', 'val2' => 'label2'], 'val2) ->multiple();
and for drop-down selects;, (*13)
echo Form::choices('test', [ 'val1' => 'label1', 'val2' => 'label2'], 'val2) ->expand(false);
To see WScore.Html
working in the demo,, (*14)
$ 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., (*15)