当我错误地点击提交按钮时,我的模型函数没有获得帖子数据信息。在应该继续处理的地方,当有一个已经准备好的数据库名时,它总是说不正确的数据库名。
所有输入数组都工作正常,只需要能够在同一个控制器上获取该信息。
$data['db_hostname'] = $this->input->post('db_hostname');
$data['db_username'] = $this->input->post('db_username');
$data['db_password'] = $this->input->post('db_password');
$data['db_database'] = $this->input->post('db_database');
$data['db_driver'] = $this->input->post('db_driver');
$data['db_prefix'] = $this->input->post('db_prefix');
$this->load->model('model_install');
$this->model_install->database($this->input->post(NULL, TRUE));
尝试
$this->model_install->database($this->input->post());
尝试
$this->model_install->database($this->input->get());
尝试
$this->model_install->database($this->input->get_post());
On My Model
public function database() {
$data['db_prefix'] = $this->input->post('db_prefix');
$file = FCPATH . '/codeigniter.sql';
if (!file_exists($file)) {
exit('Could not load sql file: ' . $file);
}
$lines = file($file);
if ($lines) {
$sql = '';
foreach($lines as $line) {
if ($line && (substr($line, 0, 2) != '--') && (substr($line, 0, 1) != '#')) {
$sql .= $line;
if (preg_match('/;'s*$/', $line)) {
$sql = str_replace("DROP TABLE IF EXISTS `", "DROP TABLE IF EXISTS `" . $data['db_prefix'], $sql);
$sql = str_replace("CREATE TABLE `", "CREATE TABLE `" . $data['db_prefix'], $sql);
$sql = str_replace("INSERT INTO `", "INSERT INTO `" . $data['db_prefix'], $sql);
$this->db->query($sql);
$sql = '';
}
}
}
}
}
首先以数组形式获取所有post数据,然后将该数组发送给模型函数。
获取post数据
$xxxx=$this->input->post('yyyy');
在数组
中存储post数据 $data=array(
'field_name_in_table'=>$xxxx
);
发送给模型
$this->model_install->database($data);
模型函数为
public function database($dat) {
if ($this->db->insert('table_name', $dat)) {
return $this->db->insert_id();
} else {
return false;
}
}