2016-04-14 45 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(); 
} 

我該如何做出錯誤信息。還有成功的消息。 ?? 1.我去註冊他給我錯誤在同一頁我們成功的頁面。 2.當我成功註冊hes給我在第二頁的成功消息。 3.我有1個模型= reg.php 4.我有1個constroler = home.php 5. 1有2個視圖= 1 reg.php 2. = reg_susses.phpCodeigniter成功或錯誤

回答

1

一,不請致電您的保存方法爲錯誤,這是誤導。

當您保存和表單驗證通過,則可以將用戶重定向到成功頁面:

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

在您看來,您可以顯示這樣的錯誤信息:

<div> 
<?php echo validation_errors() ?> 
</div>