Izzy 发表于 2014-7-25 15:54:39

新手求助 实现创建新闻条目

我在linux服务器学习架设网站
在实现用户手册中创建新闻条目的时候我出现了个问题
在 XXX/CodeIgniter_2.2.0/index.php/news/create 目录下执行新建新闻条目的时候 点击create
会跳转到 XXX/index.php/news/create 这个目录下 而且数据也没有输入到数据库中
查看之前的php文件 我没有将sumit定向到XXX/index.php/news/create这个目录下 为什么会跳转到这里?
之前的查看新闻目录都可以实现 就是这里无法实现
求助!

IvanCI 发表于 2014-7-25 16:14:07

代码

ForestYiqing 发表于 2014-7-25 16:25:20

config下的base url 设了没?

Izzy 发表于 2014-7-25 16:29:57

ForestYiqing 发表于 2014-7-25 16:25
config下的base url 设了没?

base url 原先是这个:$config['base_url']   = 'http://115.156.239.3/caiyc/‘;

然后我改成:$config['base_url']   = 'http://115.156.239.3/caiyc/CodeIgniter_2.2.0/';

还是不行啊


Izzy 发表于 2014-7-25 16:38:15

IvanCI 发表于 2014-7-25 16:14
代码

我是按照用户手册的代码 一模一样
代码有点乱

我贴一点

这是crate页面:
<h2>Create a news item</h2>

<?php echo validation_errors(); ?>

<?php echo form_open('news/create') ?>

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

这是控制器:
<?php
class News extends CI_Controller {

public function __construct()
      {
                parent::__construct();
                $this->load->model('news_model');
      }

public function index()
      {
                $data['news'] = $this->news_model->get_news();
                $data['title'] = 'News archive';

      $this->load->view('templates/header', $data);
      $this->load->view('news/index', $data);
      $this->load->view('templates/footer');
      }

public function view($slug)
      {
                $data['news_item'] = $this->news_model->get_news($slug);
      if (empty($data['news_item']))
      {
          if (empty($data['news_item']))
      {
                show_404();
      }

      $data['title'] = $data['news_item']['title'];

      $this->load->view('templates/header', $data);
      $this->load->view('news/view', $data);
      $this->load->view('templates/footer');
      }
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('templates/header', $data);
                   {
                $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');
      }
      }
}




IvanCI 发表于 2014-7-28 14:32:28

你可以尝试不设置 base_url , 因为你应用在子目录里面, 然后使用path_info模式?

这个应该算一个bug吧

Altair 发表于 2014-7-28 21:47:07

没有配置路由吧
页: [1]
查看完整版本: 新手求助 实现创建新闻条目