このような構造で言うと、列は次のとおりです。
ファーストネーム | セカンドネーム | ミドルネーム | 苗字
ここで、「名前」を入力する必要があるフォームがあるとします..名前の種類を指定していません。
コントローラーでは、その「名前」がデータベースにあるかどうかを確認する必要があります。
私はこのようにします:
public function actionCheckName($name){
$name = PersonName::model()->findByAttributes(array('first_name'=> $name));
//then check if the name exists in the first_name column
if(!empty($name)){
$name = PersonName::model()->findByAttributes(array('second_name'=> $name));
}
//if it's not in the first_name column...check in the second_name column
..
..and so on, i hope you get the idea
}
基本的に、ユーザーがどのタイプの名前を入力したかはわかりません...しかし、エントリが存在するかどうかをデータベースで確認する必要があります..これらの名前タイプのいずれかに含まれているかどうか。
上記のコードは動作しますが、見た目は少し...あまり良くありません..これを行うためのより良い方法はありますか? どうもありがとう!