2011-12-09 3 views
4

Im 누군가 CodeIgniter에서 성공/실패 메시지를 처리하는 방법을 알려주고 있는지 궁금합니다. 예를 들어CodeIgniter - 성공 또는 실패 메시지 표시

, 내 사이트까지 사용자가 로그인, 이것은 동일한 컨트롤러 (생성 프로파일)에

if (!is_null($data = $this->auth->create_user($this->form_validation->set_value('username'), $this->form_validation->set_value('password')))) { 
    // Redirect to the successful controller 
    redirect('create-profile/successful'); 
} else { 
    // Redirect to the unsuccessful controller 
    redirect('create-profile/unsuccessful'); 
} 

그런 다음 컨트롤러에서 발생하는 어떤 메신저 순간에하고있을 때, 나는 2가 이 다음과 같은

function successful() 
{ 
    $data['h1title'] = 'Successful Registration'; 
    $data['subtext'] = '<p>Test to go here</p>'; 

    // Load the message page 
    $this->load->view('message',$data); 
} 

문제처럼 방법은 단순히 site.com/create-profile/successful에 갈 수 있으며이 페이지를 표시하는 것입니다.

다른 사람이 나에게 더 나은 처리 방법을 제시 할 수 있다면 크게 환영 할 것입니다.

건배,

+0

플래시 세션 데이터를 사용하는 방법에 대한 생각. 모든 성공/실패에 대해 별도의 페이지를 작성하는 대신 세션 데이터를 감지 할 때마다 경고 또는 성공 메시지를 인쇄하는 것이 훨씬 더 효율적입니다. – user482594

답변

4

이 사용하지 않는 이유가 여기있다 :

은 몇 가지 예제 코드입니다 리디렉션 :

$this->session->set_flashdata('create_profile_successful', $some_data); 
redirect('create-profile/successful'); 

 

function successful(){ 
    if(FALSE == ($data = $this->session->flashdata('create_profile_successful'))){ 
     redirect('/'); 
    } 

    $data['h1title'] = 'Successful Registration'; 
    $data['subtext'] = '<p>Test to go here</p>'; 

    // Load the message page 
    $this->load->view('message',$data); 
} 
+0

흠, 그건 이해가되는 것처럼 보입니다 ... 이것은 여분의 URL 세그먼트를 없애 버릴 것입니다. – BigJobbies

2

리디렉션하는 대신 다른보기를 표시하십시오. 당신은 전에 flashdata을 설정할 수

if (!is_null($data = $this->auth->create_user($this->form_validation->set_value('username'), $this->form_validation->set_value('password')))) { 
    $data['h1title'] = 'Successful Registration'; 
    $data['subtext'] = '<p>Test to go here</p>'; 

    // Load the message page 
    $this->load->view('message',$data); 
} else { 
    $data['h1title'] = 'Unsuccessful Registration'; 
    $data['subtext'] = '<p>Test to go here</p>'; 

    // Load the message page 
    $this->load->view('message',$data); 
} 

접견, 스테판

6

:

if ($this->input->server('REQUEST_METHOD') == 'POST') 
{ 
    // handle form submission 
    if (!is_null($data = $this->auth->create_user($this->form_validation->set_value('username'), $this->form_validation->set_value('password')))) 
    { 
     // show success page 
     $data['h1title'] = 'Successful Registration'; 
     $data['subtext'] = '<p>Test to go here</p>'; 

     // Load the message page 
     $this->load->view('message',$data) 
    } 
    else 
    { 
     // show unsuccessful page 
     $data['h1title'] = 'Unsuccessful Registration'; 
     $data['subtext'] = '<p>Test to go here</p>'; 

     // Load the message page 
     $this->load->view('message',$data) 
    } 
} 
else 
{ 
    // show login page 
    $data['h1title'] = 'Login'; 
    $data['subtext'] = '<p>Test to go here</p>'; 

    // Load the message page 
    $this->load->view('login',$data) 
} 
관련 문제