CodeIgniter Forums
html_helper - some small changes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: html_helper - some small changes (/showthread.php?tid=14116)



html_helper - some small changes - El Forum - 12-18-2008

[eluser]bgougent[/eluser]
Like mentioned in the users guide any type of helper, library etc can be extended.

There are some basic things I was missing in the html_helper:
A <hr /> and a good print_r function.
So I made this small solution (file is called MY_html_helper.php and is placed in the helper folder of the application)

Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// ------------------------------------------------------------------------

/**
* Generates HTML HR tags based on number supplied
*
* @access    public
* @param    integer
* @return    string
*/    
if ( ! function_exists('hr'))
{
    function hr($num = 1)
    {
        return str_repeat("<hr />", $num);
    }
}

// ------------------------------------------------------------------------

/**
* Generates PHP print_r with <pre> </pre> tags
*
* @access  public
* @param   integer
* @return  string
*/  
if ( ! function_exists('pre'))
{
   function pre($array)
   {
      return '<pre>'. print_r($array, true).'</pre>';
   }
}
// ------------------------------------------------------------------------
/* End of file MY_html_helper.php */
/* Location: ./application/helpers/MY_html_helper.php */

If there are some others adds please provide them. Maybe something for CI 1.7.X


html_helper - some small changes - El Forum - 12-18-2008

[eluser]cahva[/eluser]
Heh, I personally havent seen any good reason to print multiple horizontal rulers and this function definately does not help in view files. Its easier to just write <hr /> than write &lt;?php echo hr() ?&gt; Smile

In the other hand that pre function is usefull. I found my self writing that debug code all over again many times per project so that might save a few mins Wink


html_helper - some small changes - El Forum - 12-18-2008

[eluser]bgougent[/eluser]
Multiple HR is mostly not used. That is correct.
Typing <hr /> is the same like the <br />. Is use the br() a lot. And when I would like to separate blocks during debug a hr() is very easy to type.