简体   繁体   English

Codeigniter指南创建新闻项目数据未插入

[英]Codeigniter guide Create News Item data not inserting

I am following https://www.codeigniter.com/user_guide/tutorial/create_news_items.html from CI User guide . 我正在遵循《 CI用户指南》中的https://www.codeigniter.com/user_guide/tutorial/create_news_items.html

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 现在的问题是:当我继续执行“ index.php / news / create”时,数据没有插入数据库并且没有成功重定向到success.php

config/routes.php 配置/ routes.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 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 车型/ 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 . 和create.php和success.php文件与用户指南相同。 can someone point what is the fault , 有人可以指出是什么毛病,

Edited : 编辑:

create.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>

Very much thanks in advance ! 提前非常感谢! :) :)

像这样更改您的输入类型:

 <input type="text" name="title" /><br />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM