2016-03-25 8 views
-3

..E-postayı nasıl güncellemeliyim? Bu e-postayı güncellenmesi için benim doğrulama olan

$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|callback__unique_email[email]'); 

çağrı geri fonksiyonu e-posta kullanıcı profili ayarlarında e değişirse güncellenmelidir

public function _unique_email($email) { 
if ($this->crud_model->fetch_user_by_email_user_id($email,$this->session->userdata('user_id'))) { 
    return true; 
} else { 
     $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]'); 
     return true; 
     return false; 
    } 
} 

ama kullanıcı değilse herhangi bir değişiklik yapar e-posta eskisinin e-posta olmalı ve eğer e-posta değiştirirse o zaman e-posta veritabanında benzersiz olup olmadığını hava durumu kontrol ederek güncellenmelidir?

cevap

0
function index() 
    { 
     $this->load->helper(array('form', 'url')); 

     $this->load->library('form_validation'); 

     $this->form_validation->set_rules('email', 'Email', 'required|callback_email_check'); 

     if ($this->form_validation->run() == FALSE) 
     { 
      $this->load->view('form'); 
     } 
     else 
     { 

      if($this->update($email)){ 
       $this->load->view('formsuccess'); 
      } 
     } 
    } 
0
I haven't used codeIgniter for years, So I don't exactly know how things are there. But I'll try to answer your question on a general context and try to express that using the same code in your question with minor changes. 

When You want to check if the user changed his email or not you need to have his old email from database first or in a hidden field of the form, then compare the email field value with the old one will make you know if he changed it. 

Second you need to check if the email have duplicates on the database, remember you need to do this only if the user changed his email address, so just run a query with the database. if there are no existing email update the user email in database else display an error and quit. 



public function is_unique_email($email) { 
$old_email = $this->crud_model->fetch_user_email($this->session->userdata('user_id')); 
     if ($old_email == $email) { 
      return true; 
     } else { 
       $duplicates = $this->crud_model->fetch_user_by_email($email); 
       if(count($duplicates) > 0) 
       { 
       return false; 
       } 
       else 
       { 
       return true; 
       } 
      } 
     } 

uç kod buna benzer bir şeyi, sana tam kodunu veremez üzgünüm gerektiğini, Ama bu yaklaşım ile çalışabilir düşünüyorum.

Symfony, laravel veya zend gibi bazı iyi çerçevelere geçmenizi öneririm. Codeigniter, PHP 'un çok yaptığı ilk günlerden çok fazla gelişmemiştir.

İlgili konular