【问题标题】:Smiley helper codeigniter笑脸助手代码点火器
【发布时间】:2013-02-03 18:37:40
【问题描述】:

我正在使用 codeigniter 笑脸助手,当我单击图像时,它仅在 textarea 中插入符号,而不是图像,我希望它在单击图像时显示图像。 我在网上搜索并找到一些插件'TinyMCE' bt 我想使用 codeigniter 库。 请帮帮我。

 <?php $this->load->library('table');

 $image_array = get_clickable_smileys(base_url().'img/smileys/', 'a');

 $col_array = $this->table->make_columns($image_array, 8);

$data1['smiley_table'] = $this->table->generate($col_array);?>  

<?php echo smiley_js(); ?>
<textarea id='a'></textarea><p>Click to insert a smiley!</p>

<?php echo $data1['smiley_table']; ?>

【问题讨论】:

    标签: php javascript codeigniter


    【解决方案1】:

    Smiley Helper 稍后在您显示页面时使用符号来表示图像,这就是它的工作原理。如果您想要 textarea 中的实际图像,您最好查看 tinymce 或其他所见即所得。

    【讨论】:

    • 对于rep bt,有一个函数'parse_smileys()'可以将微笑替换为文本区域中的图像bt它在读取数据后工作而不是在插入时间我们可以使用它来使用jquer onkeyup显示图像
    • 它不会在标准的 textarea 字段中创建它们。常规 textaea 无法显示图像。您在图像中看到的不是简单的标准 html 文本区域。
    • 您可以创建一个预览区域,其中将显示带有表情的更新内容。
    【解决方案2】:

    笑脸助手

    可以使用以下代码加载笑脸助手:

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

    控制器

    在您的 application/controllers/ 文件夹中,创建一个名为 smileys.php 的文件并将下面的代码放入其中。

    重要提示:更改下面 get_clickable_smileys() 函数中的 URL,使其指向您的笑脸文件夹。

    <?php
    
    class Smileys extends CI_Controller {
    
    function __construct()
    {
        parent::__construct();
    }
    
    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>
    

    当你创建了上面的控制器和视图后,访问http://www.example.com/index.php/smileys/加载它

    【讨论】:

    • 感谢您的努力,但我的问题是如何插入图片而不是字符。我上面的代码与您发布的代码相同。
    【解决方案3】:

    parse_smileys()

    将一串文本作为输入,并将任何包含的纯文本笑脸替换为等效图像。第一个参数必须包含您的字符串,第二个参数必须包含您笑脸文件夹的 URL:

    更多详情: https://ellislab.com/codeigniter/user-guide/helpers/smiley_helper.html

    【讨论】:

      猜你喜欢
      • 2020-05-27
      • 1970-01-01
      • 1970-01-01
      • 2012-02-09
      • 2011-06-04
      • 2016-01-28
      • 2012-06-30
      • 2012-02-21
      • 2011-03-29
      相关资源
      最近更新 更多