2011-09-15 10 views
0

CodeIgniterアプリケーションには検索エンジンがあり、条件に結果を追加したい。 モデルにあるコードの一部:CodeIgniterで構築された検索エンジンに条件を設定する方法

私が要求する条件にNULLに変更するにはどうすればよい
$users = $this->search_model->getUsers(NULL) 

:私が持っているコントローラで

$this->db->select(users.country_symbol); 

function getUsers($conditions=array()) 
{ 
    //Check For Conditions 
    if (is_array($conditions) and count($conditions)>0)  
     $this->db->where($conditions); 
} 

$this->loggedInUser->country_symbolと同じcountry_symbolのユーザーですか?

function getUsers($conditions = array()) 
{ 
    if (is_array($conditions) && count($conditions) > 0) { 
     foreach ($conditions as $condition) { 
      $this->db->where($condition['where'], $condition['value']); 
     } 
    } 

    // return results... 
} 

をそして、あなたはこれを行うことができます:

答えて

0

あなたはこのようなあなたの機能を変更することができ

$conditions = array(
    array('where' => 'country_symbol =', 'value' => $this->loggedInUser->country_symbol), 
    array('where' => 'zip_code', 'value' => '12345'), 
    // and so on... 
) 

$users = $this->search_model->getUsers($conditions); 

私はこのコードをテストしていませんが、それが基本的な考え方です。条件配列をループし、各条件を$this->db->where()またはそれに類する関数で適用する必要があります。

関連する問題