×

CodeIgniter Smiley Helper

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

$this->load->helper(‘smiley’);

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

get_clickable_smileys ($image_url [, $alias = ‘ ‘ [, $smileys = NULL ] ] );

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

<?php
class Online extends CI_Controller
{
    public function get_smiley_faces()
    {  
  $this->load->helper('smiley');
       echo "<title> Tutorial and Example </title>";
         $data = get_clickable_smileys('/CodeIgniter-3.1.11/smileys/smileys', 'Hello', FALSE);
      print_r($data);
          }
}
?> 

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

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

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

 <?php echo smiley_js() ;?>  /* It is the predefined JavaScript files in the smiley helper */
  • parse_smiley (): This function allows the user to send text messages with smiley images in the form.

Syntax

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

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

<?php
class Online extends CI_Controller
{
    public function parse_smiley_faces()
    {  
  $this->load->helper('smiley');
       echo "<title> Tutorial and Example </title>";
 $string = ':coolhmm: Welcome to the Tutorial and Example :-)  :roll: ';
$string = parse_smileys($string, '/CodeIgniter-3.1.11/smileys/smileys' );
echo $string;    
      }
}
?> 

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

<?php
class Online extends CI_Controller
{
    public function smiley_faces()  // it is the function that call on the URL
    {   
       echo "<title> Tutorial and Example </title>";
              $this->load->helper('smiley'); // load smiley helper
       $this->load->library('table');   // load library table
                                                // It is the get_clickable_smileys() function
       $show_image = get_clickable_smileys ( '/CodeIgniter-3.1.11/smileys/smileys', 'comments' );
       $ver_array = $this->table->make_columns($show_image, 7);
       $data['smiley_table'] = $this->table->generate($ver_array);
       $this->load->view ('smiley_face', $data);  /* call the smiley_faces.php views file in controller */
}
}
?> 

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

<html>
        <head>
                <title>Tutorial and Example</title>
                <?php echo smiley_js(); ?>  // call smiley_js file
        </head>
        <body>
                <form name="smiley">
                <h3> Hey Dude, If you want to check the name of each smiley faces, click on the faces. </h3>
                <?php echo $smiley_table; ?>
                        <textarea name="comments" id="comments" cols="50" rows="5"> </textarea>
</form>
</body>
</html> 

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

Related Topics

CodeIgniter Inflector Helper

The inflector helper file contains some predefined function that allows users to change their English words into plural, singular, and camel case, etc. Loading an Inflector Helper Before using an inflector helper function, you must...

3 minutes read.

CodeIgniter Input Class

Input Class The CodeIgniter framework provides an input class that includes various input functions to pre-process global input data for protection; furthermore, it also provides some helper functions to obtain input data. This...

11 minutes read.

CodeIgniter Routes

The Routes are used to handle URL requests on the browser. It matches the URL request to the predefined routes in CodeIgniter. Therefore, a file must be predefined as a routes.php file to...

6 minutes read.

CodeIgniter Models

Models are the classes that deals with backend operations. It is used to fetch the data from the database and send it to the Controller. All the database related information provided inside...

5 minutes read.

CodeIgniter Form Helper

A form helper file contains different functions that works with forms. It is used to create various functionality in a form such as dropdown, radio button, password, upload, hidden data, etc. These functionalities...

12 minutes read.

CodeIgniter Shopping Cart Class

It contains the various function that enables the user to add or update, display, and delete data item from the shopping carts while browsing the site. The items added in the cart...

10 minutes read.

CodeIgniter Calendaring Library

The calendar library contains various functions that are used to create a dynamic calendar. It also enables you to pass the data to calendar cells and 100% control over the calendar design. Load...

7 minutes read.

CodeIgniter Helpers

The Helpers (functions) are stored in the Helper file. It helps CodeIgniter to perform different tasks. The helper file is the collection of many functions that is used to perform specific task. It...

3 minutes read.

CodeIgniter Pagination Class

Pagination Class The CodeIgniter framework provides a pagination class that is used in the data list to create pagination links in a web application. Generally, it is used to retrieve data records from...

10 minutes read.

Calendaring Class CodeIgniter

Calendaring Class The calendar library contains various functions that are used to create a dynamic calendar. It also enables you to pass the data to calendar cells and 100% control over the calendar...

6 minutes read.

CodeIgniter Views

A View is a presentational part which shows the information to the users. It is a complex web page which contains navbar, header, footer, sidebar, etc. A view file cannot be called directly...

5 minutes read.

CodeIgniter CAPTCHA Helper

A CAPTCHA (Complete Automated Public Turning test to tell Computer and Humans Apart) helper is a function that is used in web application to check whether the user is human or machine. It...

3 minutes read.

How to remove an index.php file from the Codeigniter URLs?

As we know, a URL in CodeIgniter is designed in such a way that it would be search engine and human friendly, too, rather than using a standard approach to create a...

2 minutes read.

Image Manipulation Codeigniter

Image Manipulation A Codeigniter provides an image manipulation class that is used for resizing, cropping, rotation, and many other manipulation tasks. This class also support three major image libraries such as GD/GD2, NetPBM, and...

11 minutes read.

Insert data to the database CodeIgniter

After successfully creating a database connection with the CodeIgniter application, we will now understand how we can insert records into the database. To insert a record into a database table, Codeigniter provides...

8 minutes read.

Versions of CodeIgniter

CodeIgniter v3.1.11 (This is the current version which we will used in this tutorial)CodeIgniter v3.1.10CodeIgniter v3.1.9CodeIgniter v3.1.8CodeIgniter v3.1.7CodeIgniter v3.1.6CodeIgniter v3.1.5CodeIgniter v3.1.4CodeIgniter v3.1.3CodeIgniter v3.1.2CodeIgniter v3.1.1CodeIgniter v3.1.0CodeIgniter v3.0.6CodeIgniter...

1 minute read.

HTML Table Class CodeIgniter

HTML Table Class The CodeIgniter framework provides an HTML Table Class that is used to develop an auto-generated table using a defined array or result sets of the database table. Loading an HTML Table Class...

8 minutes read.

CodeIgniter User Agent Class

User Agent Class The CodeIgniter provides a user agent class that helps to identify and collect information about the browser, mobile devices, or robots visiting your site. Besides this, it is also used...

4 minutes read.

CodeIgniter Benchmarking Class

The CodeIgniter contains the Benchmarking class that is used to calculate the time difference between two points or the memory usage of the passed statements in the application. By default, the Benchmarking...

7 minutes read.

Download Helper Codeigniter

Download Helper Codeigniter: The download helper function is used to download data from the server to your computer. The data can be any format like text, jpg, mp3, mp4, etc. Loading...

2 minutes read.