2012-03-08 59 views
0

我正在嘗試爲我的單元模型構建一個分頁查找調用。我需要的條件是,它尋找單位類型的公寓和rentalco,房子和rentalco,但不rentalco和酒店。此外,我有我的代碼的方式措辭,蛋糕只返回rentalco的單位類型。複雜的查找語句,不知道如何爲一個條件寫多個值

public function view($type=null) { 
$this->set('title', 'All '.$type.' in and near Gulf Shores'); 
$this->set('featured', $this->Unit->getFeatured()); 
$this->paginate['Unit']=array(
     'limit'=>9, 
     'order' => 'RAND()', 
     'contain'=>array(
       'User'=>array('id'), 
       'Location', 
       'Complex', 
       'Image' 
        ), 
     'conditions'=>array(
       'Unit.type'=>array($type, 'rentalco'), 
       'Unit.active'=>1) 
    ); 
    $data = $this->paginate('Unit'); 
    $this->set('allaccommodations', $data); 
$this->set('type', $type); 
} 

UPDATE我想通了,爲什麼我的發現語句不工作(只是已經這個詞的公寓,而不是公寓突入我的瀏覽器吧.... DERP DERP);然而,我仍然很想知道我怎麼能告訴蛋糕,不要讓酒店和rentalco都能找到。

回答

0

您正在尋找NOT。它會是這樣的:

'conditions' => array(
    'NOT' => array('Unit.type' => array('hotel', 'rentalco')), 
), 

更具體地說,我需要看到你的模型架構。

+0

工作。我在手冊中看到了NOT語句,但我沒有意識到它會作爲「不是這兩個一起」的選項。謝謝! – huzzah 2012-03-09 15:14:12