2011-12-09 19 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

Hmmm、これは意味をなさないようです...これにより、余分な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) 
} 
関連する問題