Tutorialsplane

Codeigniter Html Helper


Codeigniter Html Helper – Codeigniter html helper provides various functions which is used to create Heading , image, Link and List Tags. $this->load->helper(‘html’); is used to load the helper. The html helper file contains functions that assist in working with html. Here in this tutorial we are going to explain how to use html helper in codeigniter.


Codeigniter html helper example

Let us first see how to load html helper in codeigniter and then use its function-

Load html helper

How to load html helper in codeingniter example:

 
$this->load->helper('html');

Functions:-

There are many functions are available in html helper. Now we will explain one by one with example.

1. HTML heading tag

Syntax of heading tags function is

Syntax of heading tags function is:-

heading([$data = ''[$h = '1'[$attributes = '']]])		

    Parameters:

  • $data (string) : Content
  • $heading (string) : Heading level
  • $attributes (mixed) : HTML attributes
  • Returns : HTML heading tag
  • Return type : String

EXAMPLE

Here is simple example of html heading tags.

Html heading tags in codeigniter example:-

//Controllers part
public function heading()
	{
		$this->load->helper('html');
		$this->load->view('heading_view');
	}

// Views parts

<?php echo heading('Welcome!', 3, 'class="pink"');??>
<?php $attributes = array('class' =?> 'mycustomclass','style' => 'color: red;');?>
<?php echo heading('Welcome!', 3, $attributes);??>
<?php echo heading('How are you?', 4, array('id' =?> 'question', 'class' => 'green', 'style' => 'color:green'));?>

The output of the above example will be something like this –

2. Html image tag

Syntax of image Tags function is

Syntax of image tags function is:-

img([$src = ''[$index_page = FALSE[$attributes = '']]])		

    Parameters:

  • $src (string) : Image source data
  • $index_page (bool) : Whether to treat $src as a routed URI string
  • $attributes (array) : HTML attributes
  • Returns : HTML image tag
  • Return type : String

EXAMPLE

Here is simple example of html image tags.

Html image Tags in codeigniter example:-

// Views parts
//<?php echo img('images src');??>
//<?php echo img('images src', TRUE);??>
<h3>Image Location</h3>
<?php $image = array(
        'src'   =?> 'uploads/Desert.jpg',
        'alt'   => 'Me, demonstrating how to eat 4 slices of pizza at one time',
        'class' => 'post_images',
        'width' => '200',
        'height'=> '200',
        'title' => 'That was quite a night',
        'rel'   => 'lightbox');?>

<?php echo img($image);??>

The output of the above example will be something like this –

3. Html link tag

Syntax of link tags function is

Syntax of link tags function is:-

link_tag([$href = ''[$rel = 'stylesheet'[$type = 'text/css'[$title = ''[$media = ''[$index_page = FALSE]]]]]])		

    Parameters:

  • $href (string) : What are we linking to
  • $rel (string) : Relation type
  • $type (string) : Type of the related document
  • $title (string) : Link title
  • $media (string) : Media type
  • $index_page (bool) : Whether to treat $src as a routed URI string
  • Return : HTML link tag
  • Return type : String

EXAMPLE

Here is simple example of html link tags. Which is used to connect external css and javascript file.

Html link tags in codeigniter example:-

// Views parts
<?php $link = array(
        'href'  =?> 'css file path',
        'rel'   => 'stylesheet',
        'type'  => 'text/css',
        'media' => 'text'
);?>
<h2>Welcome To Solid Coupon</h2>
<?php echo link_tag($link);??>

The output of the above example will be something like this –

3. Html list tag

There are two types Of list tags
1. Unordered list.
2. Ordered list.

Syntax of link tags function is:-

ul($list[$attributes = ''])
ol($list, $attributes = '')		

    Parameters:

  • $list (array) : List entries
  • $attributes (array) : HTML attributes
  • Return : HTML list tag
  • Return type : String

EXAMPLE

Here is simple example of html list tags.

Html list tags in codeigniter example:-

// Views parts
// Unordered List
<h3> Unordered List</h3>
<?php $list = array('colors'  =?> array('red','blue','green'),
'shapes'  => array('round','square','circles' => array(
'ellipse','oval','sphere')),);?>
<?php $attributes = array('class' =?> 'boldlist','id' => 'mylist','style' => 'color: green;');?>
<?php echo ul($list, $attributes);??>
// Ordered List
<?php $list = array('red','blue','green','yellow','grey','white');??>
<?php $attributes = array('class' =?> 'boldlist','id' => 'mylist','style' => 'color: red;');?>
<?php echo ol($list, $attributes);??>

The output of the above example will be something like this –

3. Html line break tag

Syntax of line break tags is:-

Syntax of line break tags function is:-

br([$count = 1])		

    Parameters:

  • $count (int) : Number of times to repeat the tag
  • Return : HTML line Break tag
  • Return type : String

EXAMPLE

Here is simple example of html line break tags.

Html line break tags in codeigniter example:-

// Views parts
echo br(3);

This Tag will produce three times break in code section like this-

3. Html non breaking space tag

Syntax of non breaking space tag is:-

Syntax of non breaking space tag function is:-

nbs([$num = 1])		

    Parameters:

  • $num (int) : Number of space entities to produce
  • Return : A sequence of non-breaking space HTML entities
  • Return type : String

EXAMPLE

Here is simple example of html non breaking space tag.

Html non breaking space tag in codeigniter example:-

// Views parts
echo nbs(3);

This Tag will produce three times non-breaking spaces ( )in Single Line Code like this-

Models

Connect Database

Helpers

Libraries

Helper Reference

Library Reference

Database Reference