【发布时间】:2017-01-18 21:16:57
【问题描述】:
这是我的控制器代码
public function create($postdate)
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->helper('url');
// $postdate = $this->uri->segment(3);
echo $postdate;
$data['title'] = 'Hey there!';
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('text', 'Text', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('pages/create',);
$this->load->view('templates/footer');
}
else
{
$this->news_model->set_news($postdate = 20160824);
$this->load->view('pages/success');
}
}
这是我的模型代码:
public function set_news($postdate)
{
$this->load->helper('url');
$slug = url_title($this->input->post('title'), 'dash', TRUE);
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'text' => $this->input->post('text'),
'room_date' => $postdate
);
return $this->db->insert('news', $data);
}
但模型没有将值 $postdate 插入数据库。它插入默认值 20160824,其中控制器中的回显显示作为参数传递的值,即我想在数据库中插入的(正确的)值。
【问题讨论】:
-
room_date 列的数据类型是?
-
我是 codeignitor 的新手,因此我将表单提交给 create() 本身。这导致了问题。解决了。!
标签: php codeigniter codeigniter-2 codeigniter-3