Smiley helper in codeigniter

Smiley Helper

The Smiley Helper file contains functions that let you manage smileys (emoticons).

The Smiley helper is DEPRECATED and should not be used. It is currently only kept for backwards compatibility.

Loading this Helper

This helper is loaded using the following code:


The Smiley helper has a renderer that takes plain text smileys, like 🙂 and turns them into a image representation, like smile!

It also lets you display a set of smiley images that when clicked will be inserted into a form field. For example, if you have a blog that allows user commenting you can show the smileys next to the comment form. Your users can click a desired smiley and with the help of some JavaScript it will be placed into the form field.

Clickable Smileys Tutorial

Here is an example demonstrating how you might create a set of clickable smileys next to a form field. This example requires that you first download and install the smiley images, then create a controller and the View as described.


Before you begin, please download the smiley images and put them in a publicly accessible place on your server. This helper also assumes you have the smiley replacement array located at application/config/smileys.php

The Controller

In your application/controllers/ directory, create a file called Smileys.php and place the code below in it.


Change the URL in the get_clickable_smileys() function below so that it points to your smiley folder.

You’ll notice that in addition to the smiley helper, we are also using the Table Class:

In your application/views/ directory, create a file called smiley_view.php and place this code in it:

Field Aliases

When making changes to a view it can be inconvenient to have the field id in the controller. To work around this, you can give your smiley links a generic name that will be tied to a specific id in your view.

To map the alias to the field id, pass them both into the smiley_js() function:

Available Functions
get_clickable_smileys($image_url[, $alias = ”[, $smileys = NULL]])

  • $image_url (string) – URL path to the smileys directory
  • $alias (string) – Field alias
  • Returns: An array of ready to use smileys
    Return type: array

    Returns an array containing your smiley images wrapped in a clickable link. You must supply the URL to your smiley folder and a field id or field alias.


    smiley_js([$alias = ”[, $field_id = ”[, $inline = TRUE]]])

  • $alias (string) – Field alias
  • $field_id (string) – Field ID
  • $inline (bool) – Whether we’re inserting an inline smiley
  • Returns: Smiley-enabling JavaScript code
    Return type: string

    Generates the JavaScript that allows the images to be clicked and inserted into a form field. If you supplied an alias instead of an id when generating your smiley links, you need to pass the alias and corresponding form id into the function. This function is designed to be placed into the area of your web page.


    parse_smileys([$str = ”[, $image_url = ”[, $smileys = NULL]]])

  • $str (string) – Text containing smiley codes
  • $image_url (string) – URL path to the smileys directory
  • $smileys (array) – An array of smileys
  • Returns: Parsed smileys
    Return type: string

    Takes a string of text as input and replaces any contained plain text smileys into the image equivalent. The first parameter must contain your string, the second must contain the URL to your smiley folder