默認情況下,cakephp會在find()
沒有找到任何東西時返回空數組。 但如何將其設置爲顯示爲空白數組。Cakephp當沒有匹配的結果時,如何設置find()返回空數組而不是空數組
例如:
$customer = $this->Transaction->Customer->find(--conditions to return 0 result.--)
我想讓它顯示爲空白陣列這樣。
array('Customer' => array('customer_id'=>null, 'name'=>null, 'lastname'=>null))
不僅僅是空一個像
array()
或null
因爲我總是得到了在視圖中顯示錯誤$customer['Customer']['name']
是不確定的指數。而且我不想每次都使用isset()
或is_null()
進行檢查。
是的,我使用查找 - >( '第一')。而找到 - >( '全部') – user447172
就是我的回答對你合適需要?如果沒有,你可以粘貼你在視圖中使用的代碼嗎? – cornelb
對於我的問題,您的回答是可以的,每次更新客戶表時,默認數組必須更改。我會盡力找到解決這個問題的方法,併合並數組,謝謝。 – user447172