使用 Codeigniter 的验证码不起作用

Captcha using Codeigniter is not working

我的 codeigniter 验证码不显示验证码图像。

 public  function captcha_example(){
    $this->load->helper("captcha");
    $vals = array(
        'word'          => 'Random word',
        'img_path'      => base_url().'img/photos/',
        'img_url'       => base_url().'img/photos/',
        'font_path'     =>  base_url().'system/fonts/texb.ttf',
        'img_width'     => 150,
        'img_height'    => 30,
        'expiration'    => 7200,

    );

    $cap = create_captcha($vals);
    echo $cap['image'];
    //echo  $vals['img_url'];

    $this->load->view('captcha_view');
}

我没明白这段代码有什么问题...

请在控制器中尝试:

$data['cap'] = create_captcha($vals);
$this->load->view('captcha_view', $data);

然后在视图中:

echo form_input($cap);

更新**

也不要使用基础url,只需

    'img_path'      => 'img/photos/',
    'img_url'       => 'img/photos/',
    'font_path'     =>  'system/fonts/texb.ttf',

控制器:Captcha.php

class 验证码扩展 CI_Controller {

public  function captcha_example(){
    $this->load->helper("captcha");
    $this->load->helper('form');
    $vals = array(
        'word'          => 'Random word',
        'img_path'      => base_url().'img/photos/',
        'img_url'       => base_url().'img/photos/',
        'font_path'     =>  base_url().'system/fonts/texb.ttf',
        'img_width'     => 150,
        'img_height'    => 30,
        'expiration'    => 7200,

    );

    $data['cap'] = create_captcha($vals);
    $this->load->view('captcha_view', $data);
    //echo  $vals['img_url'];


}

}

查看:captcha.php

echo form_input($cap);