2016-04-14 6 views
-2
public function index() 
{ 
    $this->load->view('home'); 
    $this->load->model('reg', 'reg'); 
    $reg = $this->reg->getItems(); 
    $data['reg'] = $reg; 
} 

public function error() 
{ 
    $this -> form_validation -> set_rules('username', 'Lietotājvārds', 'is_unique[reg.username]', 'alpha'); 
    $this -> form_validation -> set_rules('fname', 'Vārds', 'required', 'greater_than[3]'); 
    $this -> form_validation -> set_rules('lname', 'Uzvārds', 'required', 'alpha_dash', 'valid_email'); 
    $this -> form_validation -> set_rules('pw', 'Parole' , 'required'); 
    $this -> form_validation -> set_rules('pw2', 'Atkārtotā Parole' , 'required'); 
    $this -> form_validation -> set_rules('email', 'Emails' , 'required', 'valid_email'); 
    $this -> form_validation -> set_rules('email2', 'Atkārtotais Emails' , 'required', 'valid_email'); 

    $this->form_validation->set_message('required', '{field} 😌 Opā Kāda kļūda.'); 
    if ($this->form_validation->run()) 
    { 
     $reg['username'] = $this->input->post('username'); 
     $reg['fname'] = $this->input->post('fname'); 
     $reg['lname'] = $this->input->post('lname'); 
     $reg['pw'] = $this->input->post('pw'); 
     $reg['pw2'] = $this->input->post('pw2'); 
     $reg['email'] = $this->input->post('email'); 
     $reg['email2'] = $this->input->post('email2'); 
     $this->load->model('reg'); 
     $this -> reg -> saveItem($reg); 
    } 
    $this->reg_susses(); 
} 

どのようにエラーメッセージを出すことができますか。とsuccestメッセージ。 ?? 1.私は彼が同じページ私たちSuccestページで私にエラーを与えるレジスタに行く。 2.私は成功記録hesが私に2番目のページで最も優秀なmesageを与える。 3.私は1つのモデル= reg.php 4.私が持っている1 constroler = home.php 5. 1持っている2ビュー= 1 reg.php 2 = reg_susses.phpコードネイターが成功またはエラー

答えて

1

まず、ありませんエラーという保存方法を呼び出すと、誤解を招く恐れがあります。

あなたが保存し、フォーム検証通過、あなたは成功のページにユーザーをリダイレクトすることができます。

<div> 
<?php echo validation_errors() ?> 
</div> 
:あなたのビューで

public function save() 
{ 
    $this->form_validation->set_rules('username', 'Lietotājvārds', 'is_unique[reg.username]', 'alpha'); 
    $this->form_validation->set_rules('fname', 'Vārds', 'required', 'greater_than[3]'); 
    $this->form_validation->set_rules('lname', 'Uzvārds', 'required', 'alpha_dash', 'valid_email'); 
    $this->form_validation->set_rules('pw', 'Parole', 'required'); 
    $this->form_validation->set_rules('pw2', 'Atkārtotā Parole', 'required'); 
    $this->form_validation->set_rules('email', 'Emails', 'required', 'valid_email'); 
    $this->form_validation->set_rules('email2', 'Atkārtotais Emails', 'required', 'valid_email'); 

    $this->form_validation->set_message('required', '{field} &#x1F60C; Opā Kāda kļūda.'); 
    if ($this->form_validation->run()) { 
     $reg['username'] = $this->input->post('username'); 
     $reg['fname'] = $this->input->post('fname'); 
     $reg['lname'] = $this->input->post('lname'); 
     $reg['pw'] = $this->input->post('pw'); 
     $reg['pw2'] = $this->input->post('pw2'); 
     $reg['email'] = $this->input->post('email'); 
     $reg['email2'] = $this->input->post('email2'); 
     $this->load->model('reg'); 
     $this->reg->saveItem($reg); 

     // Redirect the user to the success page 
     redirect('home/success'); 
    } 

    // If it fails, it will reach this point, so we can load back our view 
    $this->load->view('home'); 
} 

// This is the success page 
public function success() 
{ 
    $this->load->view('success_page'); 
} 

、次のようなエラーメッセージを表示することができます

関連する問題