2016-09-01 5 views
1

Ich versuche, mich an Codeigniter zu gewöhnen. Es tut mir leid, wenn das eine triviale oder dumme Frage ist, aber ich habe mich bemüht, die "News Section" von Codeigniters Tutorial zu haben.Codeigniter und Formular einreichen

Es ist diese Form (von 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> 

ist, die laut this Controller:

<?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'); 
      } 
     } 
} 

sollte, denke ich, wenn die Validierung ok zurückgibt, gehen Sie vor und die Daten einfügen in die db. Nun mein Problem ist, dass die Seiten laufen unter:

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

Die Submit-Button, jedoch gibt mir zu:

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

Die routes.php Datei den folgenden Code enthält:

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

Ich weiß nicht, warum das passiert. Danke für jede Hilfe.

+1

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

Antwort

1

Haben Sie Ihre base_url-Konfiguration in application/config/config.php festgelegt?

+0

Vielen Dank für Ihre Antwort. In meiner config.php gibt es diese Zeile: $ config ['base_url'] = 'localhost/coderigniter'; was sollte die base_url setzen. – moijoune

+0

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

+0

Könnte es das sein? BEEINDRUCKEND!! Vielen Dank! Ich versuche gerade Ihren Vorschlag! – moijoune