?
This document uses PHP Chinese website manual Release
Smiley Helper文件包含可讓您管理表情符號(表情圖標)的功能。
重要
笑臉助手已棄用,不應(yīng)使用。目前僅保留用于向后兼容。
加載這個幫手
概觀
Clickable表情教程
控制器
字段別名
可用功能
這個幫助器使用下面的代碼加載:
$this->load->helper('smiley');
Smiley助手有一個渲染器,它可以獲取純文本表情符號,如:-)并將它們轉(zhuǎn)換為圖像表示形式,如
它還可以讓你顯示一組笑臉圖片,當點擊時將被插入表單域。例如,如果您有允許用戶評論的博客,則可以在評論表單旁邊顯示表情圖標。您的用戶可以點擊所需的笑臉,并在一些JavaScript的幫助下將其放置在表單字段中。
下面是一個示例,演示如何在表單字段旁邊創(chuàng)建一組可點擊的表情。此示例要求您首先下載并安裝笑臉圖像,然后創(chuàng)建一個控制器和所述的視圖。
重要
在開始之前,請下載笑臉圖像并將其放置在服務(wù)器上的公共訪問位置。這位助手還假設(shè)你有笑臉替換陣列位于application/config/smileys.php
在您的應(yīng)用程序/ controllers /目錄中,創(chuàng)建一個名為Smileys.php的文件,并將下面的代碼放入其中。
重要
更改get_clickable_smileys()
以下功能中的網(wǎng)址,以便它指向您的笑臉文件夾。
您會注意到,除了笑臉助手之外,我們還使用Table Class:
<?phpclass Smileys extends CI_Controller { public function index() { $this->load->helper('smiley'); $this->load->library('table'); $image_array = get_clickable_smileys('http://example.com/images/smileys/', 'comments'); $col_array = $this->table->make_columns($image_array, 8); $data['smiley_table'] = $this->table->generate($col_array); $this->load->view('smiley_view', $data); }}
在你的application / views /目錄中,創(chuàng)建一個名為smiley_view.php的文件,并在其中放置下面的代碼:
<html> <head> <title>Smileys</title> <?php echo smiley_js(); ?> </head> <body> <form name="blog"> <textarea name="comments" id="comments" cols="40" rows="4"></textarea> </form> <p>Click to insert a smiley!</p> <?php echo $smiley_table; ?> </body> </html> When you have created the above controller and view, load it by visiting http://www.example.com/index.php/smileys/ </body></html>
對視圖進行更改時,在控制器中使用字段標識可能會很不方便。要解決這個問題,你可以給你的笑臉鏈接一個通用的名字,這個名字將被綁定到你視圖中的一個特定的ID。
$image_array = get_smiley_links("http://example.com/images/smileys/", "comment_textarea_alias");
要將別名映射到字段ID,請將它們傳遞給smiley_js()
函數(shù):
$image_array = smiley_js("comment_textarea_alias", "comments");
get_clickable_smileys($image_url[, $alias = ''[, $smileys = NULL]])
參數(shù): | $ image_url(字符串) - 笑臉目錄的URL路徑$ alias(字符串) - 字段別名 |
---|---|
返回: | 一系列隨時可用的表情 |
返回類型: | 排列 |
$ image_url(字符串) - 笑臉目錄的URL路徑
$ alias(字符串) - 字段別名
Returns: An array of ready to use smileys
Return type: array
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_clickable_smileys('http://example.com/images/smileys/', 'comment');
smiley_js([$alias = ''[, $field_id = ''[, $inline = TRUE]]])
參數(shù): | $ alias(string) - 字段別名$ field_id(字符串) - 字段ID $ inline(bool) - 我們是否插入一個嵌入式笑臉 |
---|---|
返回: | 啟用Smiley的JavaScript代碼 |
返回類型: | 串 |
$ alias(字符串) - 字段別名
$ field_id(字符串) - 字段ID
$ inline(bool) - 是否插入內(nèi)嵌式笑臉
Returns: Smiley-enabling JavaScript code
Return type: string
生成允許圖像被點擊并插入到表單域的JavaScript。如果您在生成笑臉鏈接時提供了別名而不是ID,則需要將別名和相應(yīng)的表單ID傳遞到函數(shù)中。此功能被設(shè)計為放置在您的網(wǎng)頁的<head>區(qū)域。
例:
<?php echo smiley\_js(); ?>
parse_smileys([$str = ''[, $image_url = ''[, $smileys = NULL]]])
參數(shù): | $ str(string) - 包含笑臉代碼的文本$ image_url(string) - 笑臉目錄的URL路徑$ smileys(array) - 一個笑臉數(shù)組 |
---|---|
返回: | Parsed表情 |
返回類型: | 串 |
$ str(string) - 包含笑臉代碼的文本
$ image_url(字符串) - 笑臉目錄的URL路徑
$ smileys(數(shù)組) - 一組笑臉
Returns: Parsed smileys
Return type: string
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 smileys: :-) ;-)'; $str = parse_smileys($str, 'http://example.com/images/smileys/'); echo $str;