The smiley helper file contains smiley images that are used in the application for showing emotions and comments while chatting with others.

Load a Smiley Helper

Before using Smiley Helper in the CodeIgniter application, you must load the helper into the controller file by following the syntax.

Syntax

You have to download the smiley images folder from the official CodeIgniter website https://codeigniter.com/user_guide/helpers/smiley_helper.html.

The page shows a link to download smiley images, as shown in the following image.

CodeIgniter Smiley Helper

In that image, click on the download the smiley images link, and it will download a smiley zip folder, as shown below.

CodeIgniter Smiley Helper

Unzip the smiley folder and put the smileys file in CodeIgniter application such as:

CodeIgniter Smiley Helper

The function of smiley helper

  1. get_clickable_smileys (): As its name suggests, get_clickable_smileys () is used to fetch all smiley faces from the smiley directory and show the action by clicking on the smiley faces.

Syntax

It has two parameters:

  • $image_url : It defines the URL path to the smileys directory.
  • $alias : If you want to show any information on the browser with smileys faces, you can define in this parameter.

Example

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, itcalls the get_smiley_faces() and shows the output, as shown below.

CodeIgniter Smiley Helper
  • smiley_js(): It is used to generate the JavaScript code that allows the user to click on any smiley image and put it into the form fields.

Syntax

It has three parameters:

  • $alias: It defines the message you want to pass to the form during the smiley links.
  • $field_id: It defines the field id in which you want to pass a message.
  • $inline: In this field, you can define the Boolean values, if you are inserting an inline smiley. False represents that you are inserting a smiley without inline function, whereas true shows that with inline function.

Example

  • parse_smiley (): This function allows the user to send text messages with smiley images in the form.

Syntax

It has two parameters:

$str : In this field, you can define the text with smiley codes.

$image_url : It takes the image URL path to the smileys folder.

Example

Create a controller file Online.php and save it in application/controller folder 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, itcalls the parse_smiley_faces() functionand shows the output, as shown below.

CodeIgniter Smiley Helper

Create a simple Program of smiley Helper

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

Online.php

After that, create a view file smiley_faces.php and save it in application/views/Online/. Now, write the following program in your views file.

Smiley_faces.php

When you execute the above program in localhost by invoking the URL localhost/CodeIgniter-3.1.11/index.php/online, itcalls the smiley_faces() functionandshows the output, as shown below.

CodeIgniter Smiley Helper

Pin It on Pinterest

Share This