PHP Scripts - Html Helper Class - CodeCanyon
Html Helper Class his title this type of PHPScripts/Miscellaneous This time I will review,made by Sitebase, PHPScripts/Miscellaneous is sold at a price of $4 in CodeCanyon. attributes // class // clean code // elements // form // generate // html helper // input // oop // php // select // tags //Created | 18 February 11 |
Last Update | 18 February 11 |
Software Version | PHP 5.x, jQuery |
Files Included | HTML, CSS, PHP |
One of the things that can make your scripts really hard to read and take up much space are inline HTML tags. This helper class makes it possible to write inline html tags in a really simple an clean way.
Take for example the following code. It is used to show a select box and the selected variable is to choose a select item.
<?php $selected = 'green' ?><br /><select name="colors" id="colors" /><br /> <option value="red" <?php if($selected=='red') echo 'selected="selected"'; ?>>Red<br /> <option value="green" <?php if($selected=='green') echo 'selected="selected"'; ?>>Green<br /> <option value="yellow" <?php if($selected=='yellow') echo 'selected="selected"'; ?>>Yellow<br />
With the Html Helper class you will use the following code to get the same result.
echo HtmlHelper::select(id, name, values array, selected item);so this will give us the following code:
echo HtmlHelper::select('colors', 'colors', array('red' => 'Red', 'green' => 'Green', 'yellow' => 'Yellow'), 'green');
As you can see is the code with the Html Helper is much easier to understand, read and modify.
Of course does the Html Helper class not only support select but almost every Html element.
- label
- textfield
- textarea
- checkbox
- radiobutton
- select
- ul
- ol
- img
- a
- img
- style
- script
- swf (embed youtube, vimeo and other flash content)
Beside the above elements you can also use the openTag/closeTag or tag method to create any html element you want. All these methods and the tag methods have an extra attribute parameter. This way you can add any extra attributes that you want. For example to create the folloing p:
<p class="test" style="color: #F00">Hello world</p>you would use the following Html Helper code
echo HtmlHelper::tag('p', 'Hello world', array('class' => 'test', 'style' => 'color: #F00'));
As last example I show you how easy it is to show a youtube video. This will also work with custom SWF files or other videos like from Vimeo. Normally you would place the following code on your website:
<object height="390" width="480"><br /><param name="movie" value="http://www.youtube-nocookie.com/v/hCLbQ2Xf9i4?fs=1&hl=en_US&rel=0" /> <param name="allowFullScreen" value="true" /><br /><param name="allowscriptaccess" value="always" /><br /><embed allowfullscreen="true" src="http://www.youtube-nocookie.com/v/hCLbQ2Xf9i4?fs=1&hl=en_US&rel=0" allowscriptaccess="always" type="application/x-shockwave-flash" height="390" width="480"></embed><br /></object>
But with the Html helper class you could use the following code:
echo HtmlHelper::swf('http://www.youtube-nocookie.com/v/hCLbQ2Xf9i4?fs=1&hl=en_US&rel=0', 480, 390, null, array('allowscriptaccess' => 'always', 'allowfullscreen' => 'true'));
Updates
1.1 14/03/2011
- SWF method now outputs same code as SWFObject for better cross browser support
No comments:
Post a Comment