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.
In that image, click on the download the smiley images link, and it will download a smiley zip folder, as shown below.
Unzip the smiley folder and put the smileys file in CodeIgniter application such as:
The function of smiley helper
- 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.
- 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.
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.