2014-06-13 53 views
0

我調用這個在我的控制器:Cakephp 2.5。使用綁定時收到錯誤/解除綁定

public function index() { 
     $this->Product->recursive = 2; 
     $this->Product->unbindModel(array('hasMany' => array('Productproperty')), true); 
     $this->Product->Ranking->unbindModel(array('belongsTo' => array('Product', 'Contacts')), true); 

     $this->Product->Ranking->bindModel(array('belongsTo' => array('Customer' => array('foreignKey' => false))), true); 

     $this->set('products', $this->Paginator->paginate()); 
    } 

我得到我想要的日期,該聲明是正確的調試中。 數據輸出對我來說是正確和完美的。

但我得到這個錯誤信息在屏幕上:

爲的foreach()供給

無效參數 [CORE \蛋糕\模型\數據源\ DboSource.php,線1695]

我想知道爲什麼涉及dboSource? 任何想法是什麼錯?

+0

如果你看看產生錯誤的代碼行 - 它可能是'false'。將sql日誌添加到問題將有所幫助。你最好使用可容納的問題。 ''''''''''''''''''''''''''''如果沒有條件(?)會導致無意義的結果 – AD7six

回答

0

DBOSource line 1695

foreach ($conditions as $key => $condition) { ... } 

在我看來,你只是缺少您的PAGINATE查詢 '條件'。你有沒有試過把東西放在那裏?也許在解除綁定的默認結構,並以某種方式丟失?這可能是我認爲的CakePHP錯誤。

+0

好吧,即使我添加了一些條件,如 public $ paginate = array('limit'=> 25);查詢不會改變,錯誤信息仍然存在,並且來自操作index()的調用仍然相同,這是我在這個函數中做的所有事情...... – user1555112

+0

'這可能是我認爲的CakePHP錯誤。' - 非常不可能。@ user1555112在上面的評論中,您沒有添加任何條件;您只是定義了限制。 – AD7six

+0

嘗試定義'conditions'=> array();或者只用數組中的任何一個來測試,那麼如果paginate通常在沒有條件的情況下工作,並且在unbidingModel之後突然不工作,猜測,不知道是否它的語法或問題與他的模型有關,也許就像你在關於移除foreignKey的abouve評論中提到的那樣。讓我們看看他是否會嘗試應用任何修補程序,什麼會幫助他。 – scx

0

經過重新思考結構和許多小時的試驗和錯誤... :-) 這確實是一個由我自己造成的語法錯誤。 這是我的解決方案:

public function index() { 
     $this->set('title_for_layout','Statistiken'); 
     $this->Product->recursive = 3; 
     $this->Product->unbindModel(array('hasMany' => array('Productproperty')), true); 
     $this->Product->Ranking->unbindModel(array('belongsTo' => array('Product', 'Contacts')), true); 

     $this->Product->Ranking->Contact->unbindModel(array('hasMany' => array('Ranking')), true); 

     $this->set('products', $this->Paginator->paginate()); 
    }