我的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');
}
我没有在这段代码中弄错...
答案 0 :(得分:2)
请尝试使用Controller:
$data['cap'] = create_captcha($vals);
$this->load->view('captcha_view', $data);
然后在视图中:
echo form_input($cap);
UPDATE **
也不要使用基本网址,只需
'img_path' => 'img/photos/',
'img_url' => 'img/photos/',
'font_path' => 'system/fonts/texb.ttf',
答案 1 :(得分:2)
控制器:Captcha.php
类Captcha扩展了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);