2016-09-01 13 views
1

私はCodeigniterに慣れようとしています。それが些細な言い回しなのかどうかごめんなさい。申し訳ありませんが、私はCodeigniterのチュートリアル作業の「ニュースセクション」を持つことに苦労しています。検証がOKを返す場合codeigniterとform submit

<?php 
class News extends CI_Controller { 

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

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

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

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

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


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

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

、私が思うに、先に行くと、データを挿入する必要がありますthis制御装置によれば、

このフォームがあり(hereから)

<h2><?php echo $title; ?></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> 

dbに入力します。さて、私の問題は、ページを下に実行することをされています

http://localhost/codeigniter/index.php/news/ 

送信ボタンは、しかし、に私を返します。

$route['news/create'] = 'news/create'; 
$route['news/(:any)'] = 'news/view/$1'; 
$route['news'] = 'news'; 
$route['(:any)'] = 'news/view/$1'; 
$route['default_controller'] = 'news'; 

http://localhost/codeigniter/index.php/news/localhost/codeigniter/index.php/news/create 

routes.phpのファイルには、次のコードが含まれています

なぜこれが起こっているのかわかりません。何か助けてくれてありがとう。

+1

'$ config ['base_url'] = 'http:// localhost/codeigniter /;' – Sparky

答えて

1

base_url設定をapplication/config/config.phpに設定しましたか?

+0

お返事ありがとうございます。私のconfig.phpには次の行があります:$ config ['base_url'] = 'localhost/codeigniter'; base_urlを設定する必要があります。 – moijoune

+0

これは$ config ['base_url'] = 'http:// localhost/codeigniter /'を意味します。 –

+0

これはこれでしょうか?ワオ!!ありがとう!私は今あなたの提案をしようとしています! – moijoune