The HTML helper function is used in CodeIgniter to provide various functionality, such as headings, images, links, list tags, etc.

Loading the HTML Helper

Before using the html helper function, you must load the helper in the controller’s files.

Syntax

Function of HTML Helper:

1.heading(): A heading() function is used to create a heading in the HTML form.

Syntax

It has three parameters:

  • $data: In this parameter, you have to defined the content.
  • $h: It defines the heading level in html such as 1 to 6.
  • $attributes: In this fields, you can define the html attributes such as class and id.

Example

2. img(): This function is used to display images in html pages.

Syntax

  • $src : It represents the image source path in html page.
  • $index_page : It define whether to pass $src as a routed URL string.
  • $attributes: If you want to show additional functionalities in the HTML page, you can define in this attribute.

Example

3. link_tag(): A link_tag () function is used to create links and transfer controls to some other HTML / CSS pages.

Syntax

Parameters lists:

  • $href = In this field, you can define a stylesheet link as well as other link to transfer control.
  • $rel = It defines the relation type such as stylesheet.
  • $type = It defines related file types such as text, css and javascript, which you have defined in link_tag.
  • $title = It defines the link title.
  • $media = It represents the media type in the link_tag.
  • $index_page = It defines whether you want to treat $src as a routed url string to pass control to other files.

Example

4. ul(): It defines the list of items in unordered format.

Syntax

It has two parameters:

  • $list = It contains an array of un-order list.
  • $attributes = It contains HTML attributes such as class and id that you can define in <div> tag.

Example

5. ol(): This function defines all items in the ordered structure.

Syntax

  • $list:  It contains an array of order list.
  • $attributes = It contains HTML attributes such as class and id that you can define in <div> tag.

Example

6. meta(): It is used to provide all information about an html document. The content of the meta tag doesn’t display on the web page. You can also define web page related keywords in meta tag to access in search engines.  

Syntax

Parameters list:

  • $name: It contains meta name such as keywords, content-type, robots, description in html file.
  • $content: As its name suggests, you can define the content in this parameter.
  • $type: It defines the type of meta tags such as http-equiv or name.
  • $newline: It represents the new line characters.

Example

7. br(): This generates a break tag in two continuous lines or paragraphs in an html web page. It is simple in CodeIgniter because you have to define numbers only in the br() function, and it will generate the space according to the number passed in the function.

Syntax

Example

8. nbs(): It is used to create space between two consecutive words.

Syntax

Parameter List:

$num = It contains a numerical value that is used to produce space between two or more words.

Example

Example of HTML helper

Create a controller file Online.php and save it in application/controller/. After that, write the following program in your controller file.

Online.php

When you execute the above program in localhost by invoking the URL localhost/CodeIgniter-3.1.11/index.php/online/, it shows the output, as shown below.

HTML HELPER

Pin It on Pinterest

Share This