【发布时间】: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
【问题讨论】:
-
你的
base_url是什么...你可以通过查看url来发现问题。 -
它是 $config['base_url'] = 'localhost/ci/'
-
那么我看不出它会重复 2 次的原因
-
尝试将基本网址设置为
http://localhost/ci/