×

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 Number helper

The number helper file contains some predefined function that deals with numeric data to display numbers in bytes format. Load a Number Helper You must load a number helper file in the controller to perform...

3 minutes read.

Delete a record from Database CodeIgniter

Delete a record from the Database After inserting, retrieving, and updating table records, we will now learn how we can delete a particular record from a database table. To delete a record, first, we...

6 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.

CodeIgniter Creating Library

As we know, CodeIgniter has a large collection of library functions that are stored in the system/libraries folder. CodeIgniter also provides some additional functionality in library files. For example, if you want to...

3 minutes read.

CodeIgniter Output class

Output class The CodeIgniter framework contains a core class that is an Output class. It  includes the various functions that are used to send the final web page to the requesting browser. In...

8 minutes read.

CodeIgniter Security Class

Security Class The security class provides various function that helps to create a secure application and process input data securely to the application. This class is preloaded in the CodeIgniter application, so you...

4 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.

Form Validation Library Codeigniter

Form Validation Library The Codeigniter provides a form validation library that contains predefined rules to validate the form fields. It also helps in optimizing the form validation code, which reduces the effort and time...

31 minutes read.

Database Configuration CodeIgniter

In every application, there is an important part of a database through which developers can connect an application to store users’ data and perform various functions in the database application such as inserting,...

10 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.

Installation of CodeIgniter

Before installing CodeIgniter, you need to make sure that the wamp or xampp server in the system is preinstalled. The installation procedure for CodeIgniter is very easy. You can download CodeIgniter by following these...

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.

CodeIgniter HTML Helper

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...

7 minutes read.

CodeIgniter Cookie Helper

A cookie is a small set of files sent from the web server to the end-user system. In Helpers, the cookie helper file has some predefined functions that are used to the...

4 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.

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.

Directory Helper Codeigniter

Directory Helper CodeIgniter: provides a directory helper function that works with the directory. It shows the structure of the file, hidden file in the folder, and the folder in...

3 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 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...

4 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.