Wednesday, June 20, 2012

Html Helper Class

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. Html Helper Class - CodeCanyon Item for Sale 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.

&lt;?php $selected = 'green' ?&gt;<br /><select name="colors" id="colors" /><br /> <option value="red" &lt;?php if($selected=='red') echo 'selected="selected"'; ?&gt;>Red<br /> <option value="green" &lt;?php if($selected=='green') echo 'selected="selected"'; ?&gt;>Green<br /> <option value="yellow" &lt;?php if($selected=='yellow') echo 'selected="selected"'; ?&gt;>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&amp;hl=en_US&amp;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&amp;hl=en_US&amp;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&amp;hl=en_US&amp;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

Related produck This user:Sitebase

Google Maps for Mobile Site PRO - CodeCanyon Item for Sale Twitter Wall for Mobile Site PRO - CodeCanyon Item for Sale Mobile Site PRO - CodeCanyon Item for Sale News Widget for WordPress - CodeCanyon Item for Sale Testimonials for WordPress - CodeCanyon Item for Sale API Client - CodeCanyon Item for Sale Google Analytics for Joomla - CodeCanyon Item for Sale

More items by Sitebase

No comments:

Post a Comment