Blog Details

Helper Functions


                                
                                    <h2>* <strong>What is Helper Functions</strong> ?</h2>
<ul>
	<li>Helpers, as the name suggests, <strong>help</strong> you <strong>with tasks.</strong></li>
	<li>Each helper file is simply a <strong>collection of functions</strong> in a particular <strong>category.</strong></li>
	<li>There are <dfn>URL Helpers</dfn>, that assist in <strong>creating links</strong>, there are <dfn>Form Helpers</dfn> that help you create <strong>form elements</strong>, <strong><dfn>Text Helpers</dfn></strong> perform various <strong>text formatting</strong> routines, <dfn>Cookie Helpers</dfn> <strong>set and read cookies</strong>, <strong><dfn>File Helpers</dfn> </strong>help you <strong>deal with files</strong>, etc.</li>
	<li>Unlike most other systems in CodeIgniter, Helpers are not written in an Object Oriented format.</li>
	<li>They are simple, <strong>procedural functions.</strong></li>
	<li>Each helper function performs one <strong>specific task</strong>, with <strong>no dependence</strong> on other <strong>functions</strong>.</li>
</ul>
&nbsp;
<h2>* Loading a Helper :-</h2>
<ul>
	<li>Loading a helper file is <strong>quite simple</strong> using the following function:</li>
</ul>
&nbsp;
<h3><strong>Syntax:</strong></h3>
<ul>
	<li><strong>$this-&gt;load-&gt;helper('<var>name</var>');</strong></li>
</ul>
<ul>
	<li>Where <var>name</var> is the file name of the helper, without the .php file extension or the "helper" part.</li>
</ul>
&nbsp;
<h3><strong>Example:</strong></h3>
<ul>
	<li><strong>$this-&gt;load-&gt;helper('<var>url</var>');</strong></li>
</ul>
<ul>
	<li>to load the <strong><dfn>URL Helper</dfn></strong> file, which is named <strong><var>url_helper.php</var></strong>, you would do this:</li>
</ul>
&nbsp;
<h2>* Loading Multiple Helpers :-</h2>
<ul>
	<li>If you need to load <strong>more than one helper</strong> you can specify them in an array, like this:</li>
</ul>
<ul>
	<li><strong><strong><strong><strong><strong><strong><strong>$this-&gt;load-&gt;helper(
<samp>array(</samp></strong></strong></strong></strong></strong></strong></strong></li>
</ul>
'<var>helper1</var>', '<var>helper2</var>', '<var>helper3</var>'

<samp>          )</samp>                           );

&nbsp;
<h2>* Auto-loading Helpers :-</h2>
<ul>
	<li>If you find that you need a particular helper globally throughout your application, you can tell CodeIgniter to auto-load it during system initialization.</li>
	<li>This is done by opening the <strong><var>application/config/autoload.php</var> </strong>file and adding the helper to the autoload array.</li>
</ul>
&nbsp;
<h2>* Using a Helper :-</h2>
<ul>
	<li>Once you've loaded the Helper File containing the function you intend to use, you'll call it the way you would a standard PHP function.</li>
	<li> to <strong>create a link</strong> using the <strong><dfn>anchor()</dfn></strong> function in one of your view files you would do this:</li>
</ul>
&nbsp;
<h3>Example :</h3>
<ul>
	<li><strong>&lt;?php echo anchor('blog/comments', 'Click Here');?&gt;</strong></li>
</ul>
<ul>
	<li>Where "Click Here" is the name of the link, and "blog/comments" is the URI to the controller/function you wish to link to.</li>
</ul>
&nbsp;
<h4></h4>
                                    


Categories

CodeIgnitor

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote