我从Register寄存器调用验证码模型。 " insert_captcha()模型函数加载验证码助手,更新验证码表,并将创建的验证码返回到寄存器控制器,将其显示在视图中。
它可以在50%的时间内正常工作,但我不时会得到一个很大的php错误列表:
模型的摘录:
event.preventDefault()
控制器的摘录
class captcha_model extends CI_Model {
public function __construct() {
parent::__construct();
$this->load->helper('captcha');
}
public function insert_captcha() {
//captcha creation
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url() . 'captcha',
'font_path' => './assets/fonts/OpenSans-Bold.ttf',
'img_width' => '150',
'img_height' => 30,
'expiration' => 900,
'word_length' => 8,
'font_size' => 16,
'img_id' => 'captcha-pic',
'pool' => '0123456789abcdefghijklmnopqrstuvwxyz',
'colors' => array(
'background' => array(255, 255, 255),
'border' => array(255, 255, 255),
'text' => array(0, 0, 0),
'grid' => array(255, 40, 40)
)
);
$captcha = create_captcha($vals);
//insert captcha into DB
$captcha_db_params = array(
'captcha_time' => $captcha['time'],
'ip_address' => $this->input->ip_address(),
'word' => $captcha['word']
);
$query = $this->db->insert_string('captcha', $captcha_db_params);
if ( $this->db->query($query) ) { return $captcha; }
else { return false; }
}
}
错误
class Register extends CI_Controller {
public $data = array();
public function __construct() {
parent::__construct();
$this->load->model('captcha_model');
if ($this->session->userdata('logged_in')) {
$this->data['name'] = $this->session->userdata('name');
$this->data['id'] = $this->session->userdata('id');
$this->data['email'] = $this->session->userdata('email');
$this->data['isAdmin'] = $this->session->userdata('isAdmin');
}
if (!empty($this->session->flashdata('error'))) { $this->data['error'] = $this->session->flashdata('error'); }
}
public function index() {
//captcha creation success
if ($cap = $this->captcha_model->insert_captcha()) {
$this->data['title'] = 'Register';
$this->data['captcha'] = $cap;
$this->template->load('default', 'register/register', $this->data);
}
//not supposed to happen
else {
$this->data['error'] = 'Erreur systeme, captcha non genere';
$this->template->load('default', 'register/register', $this->data);
}
}
答案 0 :(得分:0)
这是CodeIgniter错误:https://github.com/bcit-ci/CodeIgniter/issues/4427
即将发布的3.0.5版本将解决它。