|↑ Helper Reference|
|Урок - Smiley Helper|
← Предыдущий урок
Урок - Security Helper
Следующий урок →
Урок - String Helper
The Smiley Helper file contains functions that let you manage smileys (emoticons).
Loading this Helper
This helper is loaded using the following code:
The Smiley helper has a renderer that takes plain text simileys, like :-) and turns them into a image representation, like
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.
Important: 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
In your application/controllers/ folder, create a file called smileys.php and place the code below in it.
Important: 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 using the Table Class.
In your application/views/ folder, create a file called smiley_view.php and place this code in it:
When you have created the above controller and view, load it by visiting http://www.example.com/index.php/smileys/
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.
$image_array = get_smiley_links("http://example.com/images/smileys/", "comment_textarea_alias");
To map the alias to the field id, pass them both into the smiley_js function:
$image_array = smiley_js("comment_textarea_alias", "comments");
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.
$image_array = get_smiley_links("http://example.com/images/smileys/", "comment");
Note: Usage of this function without the second parameter, in combination with js_insert_smiley has been deprecated.
<?php echo smiley_js(); ?>
Note: This function replaces js_insert_smiley, which has been deprecated.
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:
$str = 'Here are some simileys: :-) ;-)'; $str = parse_smileys($str, "http://example.com/images/smileys/"); echo $str;