非常教程

Codeigniter 3参考手册

Smiley

Smiley Helper

Smiley Helper文件包含可让您管理表情符号(表情图标)的功能。

重要

笑脸助手已弃用,不应使用。目前仅保留用于向后兼容。

  • 加载这个帮手
  • 概观
  • Clickable表情教程
    • 控制器
    • 字段别名
  • 可用功能

加载这个帮手

这个帮助器使用下面的代码加载:

$this->load->helper('smiley');

概观

Smiley助手有一个渲染器,它可以获取纯文本表情符号,如:-)并将它们转换为图像表示形式,如

Smiley Helper

它还可以让你显示一组笑脸图片,当点击时将被插入表单域。例如,如果您有允许用户评论的博客,则可以在评论表单旁边显示表情图标。您的用户可以点击所需的笑脸,并在一些JavaScript的帮助下将其放置在表单字段中。

Clickable表情教程

下面是一个示例,演示如何在表单字段旁边创建一组可点击的表情。此示例要求您首先下载并安装笑脸图像,然后创建一个控制器和所述的视图。

重要

在开始之前,请下载笑脸图像并将其放置在服务器上的公共访问位置。这位助手还假设你有笑脸替换阵列位于application/config/smileys.php

控制器

在您的应用程序/ controllers /目录中,创建一个名为Smileys.php的文件,并将下面的代码放入其中。

重要

更改get_clickable_smileys()以下功能中的网址,以便它指向您的笑脸文件夹。

您会注意到,除了笑脸助手之外,我们还使用Table Class:

<?php

class 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 /目录中,创建一个名为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()函数:

$image_array = smiley_js("comment_textarea_alias", "comments");

可用功能

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

参数:

$ 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]]])

参数:

$ alias(string) - 字段别名$ field_id(字符串) - 字段ID $ inline(bool) - 我们是否插入一个嵌入式笑脸

返回:

启用S​​miley的JavaScript代码

返回类型:

  • $ alias字符串) - 字段别名
  • $ field_id字符串) - 字段ID
  • $ inlinebool) - 是否插入内嵌式笑脸
Returns:  Smiley-enabling JavaScript code
Return type:  string
生成允许图像被点击并插入到表单域的JavaScript。如果您在生成笑脸链接时提供了别名而不是ID,则需要将别名和相应的表单ID传递到函数中。此功能被设计为放置在您的网页的<head>区域。

例:

<?php echo smiley\_js(); ?>

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

参数:

$ str(string) - 包含笑脸代码的文本$ image_url(string) - 笑脸目录的URL路径$ smileys(array) - 一个笑脸数组

返回:

Parsed表情

返回类型:

  • $ strstring) - 包含笑脸代码的文本
  • $ image_url字符串) - 笑脸目录的URL路径
  • $ smileys数组) - 一组笑脸
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;

Smiley相关

Codeigniter 3

CodeIgniter 是一个PHP MVC框架,特点是超轻量级、有数据加密、有灵活URI路由等。对于 PHP 程序员来说,它小巧但功能强大。

主页 https://codeigniter.com/
源码 https://github.com/bcit-ci/CodeIgniter
版本 3
发布版本 3.1.5