2017-01-30 54 views
-2

有人可以幫我解釋一下如何在條件參數條件中應用if語句來編寫cakephp查詢。請看下面的例子:if cakephp條件中的else條件參數

$customerList = $this->Asset->find("list", array(
      "conditions" => array(
       "AUser.status" => 1, 
       'Asset.warranty_status_id' => $warranty_status_id 
       ), 
      "fields" => array("AUserProfile.user_id", "AUserProfile.company_name"), 
      'joins' => array(
       array(
        'alias' => 'AUser', 
        'table' => 'users', 
        'type' => 'LEFT', 
        'conditions' => array(
         'Asset.user_id = AUser.user_id', 
         'Asset.status = 1', 
        ) 
       ), 
       array(
        'alias' => 'AUserProfile', 
        'table' => 'user_profiles', 
        'type' => 'LEFT', 
        'conditions' => array(
         'AUser.user_id = AUserProfile.user_id', 
        ) 
       ) 
      ), 
      "order" => "AUserProfile.company_name ASC", 
      "recursive" => $recursive 
      ) 
     ); 

我需要在條件數組塊中寫條件。

+0

你能提供你想要的原始查詢嗎?這樣我們可以使用cakephp進行相同的查詢。 –

回答

0

如果我這樣做是正確,你可以使用三元運算符是這樣的:

// ... 
'conditions' => CONDITION ? VALUE_FOR_TRUE : VALUE_FOR_FALSE; 
// ... 

WHERE條件可以是相同的,你設置裏面if()語句。