【问题标题】:Error 404 Page Not Found after submitting form提交表单后找不到错误 404 页面
【发布时间】:2019-01-17 14:20:55
【问题描述】:
controller -
<?php
class News extends CI_Controller{

    public function __construct(){

        parent::__construct();
        $this->load->model('News_model');
         $this->load->helper('url_helper');

    }
public function create(){

        echo $data['title']=$data['title1'] = 'Form';
        $this->load->helper('form');
        $this->load->helper('url');
        $this->load->library('form_validation');
        $this->form_validation->set_rules('title', 'Title', 'required');
        $this->form_validation->set_rules('text', 'Text', 'required');
        $this->load->view('news/create', $data);

        if ($this->form_validation->run() === FALSE)
        {
           // $this->load->view('templates/header', $data);
            //$this->load->view('news/create');
          //  $this->load->view('templates/footer');

        }
        else
        {
            $this->news_model->set_news();
            $this->load->view('news/success');
        }
    }
}

?>

view-
<h2><?php echo $title1; ?></h2>
<?php echo validation_errors(); 
$this->load->helper('form'); ?>
<?php echo form_open(); ?>


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

model-
<?php

class News_model extends CI_Model{

    public function __construct(){

        $this->load->database();
    }

    public function getnews($slug= FALSE){

        if($slug ===  FALSE){

                $query = $this->db->get('news');
                return $query->result_array();
        }

        $query = $this->db->get_where('news' , array('slug' => $slug));
        return $query->row_array();
    }
}
?>

出现错误 - 在本地主机上提交表单时找不到 404 页面。提交表单后链接如下所示 - http://localhost/ci/index.php/news/localhost/ci/index.php/news/create

出现错误 - 在本地主机上提交表单时找不到 404 页面。提交表单后链接如下所示 - http://localhost/ci/index.php/news/localhost/ci/index.php/news/create

【问题讨论】:

标签: codeigniter codeigniter-3


【解决方案1】:

请按以下步骤操作:

1.您需要在自动加载文件中加载“url_helper”,这是一种最佳做法,而不是在每个页面中都写入。 路径(应用程序 > 配置 > autoload.php)

$autoload['helper'] = array('url');

2.您需要在视图页面顶部添加以下行。

<base href="<?php echo base_url(); ?>">

【讨论】:

    猜你喜欢
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    相关资源
    最近更新 更多