I am following https://www.codeigniter.com/user_guide/tutorial/create_news_items.html from CI User guide .
Now the problem is: when i proceed with "index.php/news/create", data not inserting into the database and not successfully redirecting to 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';
and the 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');
}
}
models/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);
}
}
and the create.php and success.php files are same as user guide . can someone point what is the fault ,
Edited :
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>
Very much thanks in advance ! :)
像这样更改您的输入类型:
<input type="text" name="title" /><br />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.