Bir kayıt veritabanında bulunamazsa zaman hataları görüntülemek için doğru yolu

0 Cevap php

Currently, I have a model that has a method called getEmails($id=NULL). If $id == NULL getEmails() uses fetchAll($select)->toArray() to return all the records in the email table. In the view I have an if statement that checks to see if the array returned is an empty array. If it is, it displays an error letting the user know that there are no emails to display, otherwise it goes through a foreach() loop to display all the emails.

Bu durumda, e-posta dizi emapty olup olmadığını kontrol deyimi eğer kullanarak edilmesi doğru mudur? Ya ben başka bir şekilde yapıyor olmalıdır?

! $ Id = null getEmails sadece bir kayıt döndürmek için aşağıdaki kodu kullanıyorsa:

        $select->where('id=?',$id);
        $row = $this->fetchRow($select)
        if(!$row) throw new Exception('Could not find email with ID '.$id);
        else return $row->toArray();

Gördüğünüz gibi kayıt bulunamadı, eğer bir istisna atar.

Gerektiğinde kullanıcıya hataları görüntüleme daha birleşik bir yol var gibi hissediyorum.

O id $ id ile e-posta bulunamadı olamaz durumunda bir özel durum için doğru mudur?

Ben bu yüzden :-) Tüm yardım için teşekkür ederim şeyler yapmanın "doğru" bir şekilde öğrenmeye çalışıyorum

0 Cevap