[英]Codeigniter guide Create News Item data not inserting
我正在遵循《 CI用戶指南》中的https://www.codeigniter.com/user_guide/tutorial/create_news_items.html 。
現在的問題是:當我繼續執行“ index.php / news / create”時,數據沒有插入數據庫並且沒有成功重定向到success.php
$route['default_controller'] = 'frontpage';
$route['404_override'] = '';
$route['(:any)'] = 'templates/view/$1';
$route['(:any)'] = 'include/view/$1';
$route['news/(:any)'] = 'news/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
和application / controller / news.php
<?php
class News extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('news_model');
}
public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
$data['title'] = 'Create a news item';
$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('include/header', $data);
$this->load->view('news/create');
$this->load->view('include/footer');
}
else
{
$this->news_model->set_news();
$this->load->view('news/success');
}
}
車型/ news_model.php
<?php
class News_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function set_news()
{
$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')
);
return $this->db->insert('news', $data);
}
}
和create.php和success.php文件與用戶指南相同。 有人可以指出是什么毛病,
編輯:
create.php
<h2>Create a news item</h2>
<?php echo validation_errors(); ?>
<?php echo form_open('index.php/news/success') ?>
<label for="title">Title</label>
<input type="input" name="title" /><br />
<label for="text">Text</label>
<textarea name="text"></textarea><br />
<input type="submit" name="submit" value="Create news item" />
</form>
提前非常感謝! :)
像這樣更改您的輸入類型:
<input type="text" name="title" /><br />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.