2016-09-01 2 views
1

저는 Codeigniter에 익숙해 지려고합니다. 그것이 사소한 질문이라면 유감이지만 Codeigniter의 튜토리얼 작업의 "News Section"을 갖기 위해 애 쓰고 있습니다.codeigniter 및 양식 submit

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

(here에서)이 양식이 있습니다

하는 this 컨트롤러에있어서, 상기 유효성 확인을 반환하는 경우

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

, 나는 생각한다, 가서 데이터를 삽입 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

application/config/config.php에서 base_url 구성을 설정 했습니까?

+0

답장을 보내 주셔서 대단히 감사합니다. 내 config.php에는 다음 줄이 있습니다 : $ config [ 'base_url'] = 'localhost/codeigniter'; base_url을 설정해야합니다. – moijoune

+0

당신은 $ config [ 'base_url'] = 'http : // localhost/codeigniter /'를 의미합니다; –

+0

그럴 수 있습니까? 와우!! 감사! 나는 너의 제안을 지금 당장 시도하고있다! – moijoune