可以在CodeIgniter Active Record中使用多个INSERT记录而不使用forach,foreach等?
我目前的代码:
foreach($tags as $tag) {
$tag = trim($tag);
$data = array(
'topic_id' => $topic_id,
'user_id' => $user_id,
'text' => $tag
);
$this->db->insert('topic_tags', $data);
}
Run Code Online (Sandbox Code Playgroud) <? if ( ! defined('BASEPATH')) exit();
class Registration extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('registration_model');
}
public function index() {
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'E-mail', 'trim|required|valid_email|callback_email_available');
if($this->form_validation->run() == FALSE) {
$this->load->view('registration');
} else {
$this->registration_model->add_user();
}
}
# Check E-mail
public function email_available($email) {
$this->db->select('email');
$this->db->where('email', $email);
$query = $this->db->get('users');
$result = $query->row();
if(!empty($result)) {
$this->form_validation->set_message('email_available', 'This e-mail belongs to another user.');
return FALSE;
} else {
return TRUE;
}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我有一份表格验证的注册表格.我有一个回调函数来验证电子邮件的唯一性.
所有代码都可以正常工作,但我可以直接访问带有错误的回调函数
examle.com/registration/email_available
A PHP Error was …Run Code Online (Sandbox Code Playgroud)