2012-01-15 4 views
2

CodeIgniter 2.1.0을 다운로드하고 CodeIgniter 2.1.0에서 tutorial을 따랐습니다. 나는이 URL에서 양식을 제출하려고 할 때URL 리디렉션이 작동하지 않는 이유는 무엇입니까?

문제는 :

페이지가이 URL로 리디렉션됩니다
http://localhost/CodeIgniter/index.php/news/create 

: 나는 route.php을 변경하는 방법은 여러 가지 피곤

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

하지만 작동하지 않습니다. 이 문제를 어떻게 해결할 수 있습니까 ??

route.php

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

이 폼 페이지에 대한 코드입니다

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

나는 페이지가로드 될 때 때 양식 페이지, 다음 코드 세그먼트가 실행됩니다 통지 그러나, else 세그먼트는 절대로 실행되도록 변경되지 않았습니다.

if ($this->form_validation->run() === FALSE) 
    { 
     $this->load->view('templates/header', $data); 
     $this->load->view('news/create'); 
     $this->load->view('templates/footer'); 

    } 

이것은 양식 페이지이며 특별한 것은 아니며 위의 작성 기능을 호출하십시오. create.php

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

이 폼 페이지의 HTML입니다 :

<html> 
<head> 
<title>Create a news item - CodeIgniter 2 Tutorial</title> 
</head> 
<body> 
<h1>CodeIgniter 2 tutorial</h1><h2>Create a news item</h2> 

<form action="localhost/CodeIgniter/index.php/news/create" method="post" accept-charset="utf-8"> 
<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><strong>&copy;2012</strong> 
</body> 
</html> 

그리고 나는 create new item 버튼을 누르면 URL이

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

페이지로 변경 보기 : 404 Pages Not Found

+0

양식의 '조치'는 무엇입니까? 나는 당신이'form_open()'을 사용하고 있다는 것을 알고 있지만, 단지 유머와 HTML 출력을 확인한다. –

+0

양식은 뉴스 제목과 뉴스 본문이 포함 된 데이터베이스에 새 뉴스를 삽입하는 것입니다. – qkzhu

+0

모든 양식에'action' 속성이 있습니다. HTML 출력에 그 값이 무엇인지 묻습니다. –

답변

6

부적절한 기본 URL 설정으로 인해 해결책을 찾았습니다. 내 기본 URL 전에

했다 :

$config['base_url'] = 'localhost/CodeIgniter';는 지금은

$config['base_url'] = 'http://localhost/CodeIgniter/'; 

로 변경하고 지금은 잘 작동합니다.

덕분에 누구를 위해 :)

0

그냥 제안을하기 위해 노력, 그것은 할 수있을 수 있습니다 당신을하는 데 도움이 :

$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http"); 
$config['base_url'] .= "://".$_SERVER['HTTP_HOST']; 
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']); 

이 config.php 파일이 설정, 당신은 $config['base_url'] 걱정하지 않습니다 . http 또는 https 포트를 설정하기 때문에 domain, port number (예 : 8080, 8880 등) 및 codeigniter root folder입니다. 또한 미래에 어떤 codeigniter 프로젝트에서도 재사용 될 수 있습니다. :)

this article

관련 문제