0
我被困在cakephp的循環函數中。 邏輯是我需要將用戶輸入的數據與已經在表中的數據進行比較。我有兩張桌子,一張是Bookings
,另一張是Inventories_Bookings
。下面是我的編碼,但它不工作。任何幫助!謝謝與數據庫中的數據輸入的匹配數據CAKEPHP
public function add2() {
if ($this->request->is('post')) {
foreach ($invbook as $invenbook)
{
if ($this->request->data['Booking']['bookings_location'] == $invenbook['InventoriesBooking']['test'])
{
$this->Session->setFlash(__('The booking cannot be created'));
$this->redirect(array('action' => 'add2'));
debug($this->request->data['Booking']['bookings_location'] == $invenbook['InventoriesBooking']['test']);
}
}
$this->Booking->create();
$invbook = $this->Booking->InventoriesBooking->find('list',array('fields' => array('InventoriesBooking.id', 'InventoriesBooking.test')));
$this->set(compact('invbook'));
}
}
「不起作用」是什麼意思?你有任何錯誤? – dhofstet
第0步:確保您的調試模式是否打開..如果不確定的地方配置::寫('調試',2);在你的add2函數中。 步驟1:調試用戶輸入的數據,在你的情況下,它可能類似debug($ this-> request-> data); 第2步:調試已經在表中的數據..我猜可能是類似調試($ invbook); 第3步:檢查您的比較$ this-> request-> data ['Booking'] ['bookings_location'] == $ invenbook ['InventoriesBooking'] ['test']是否正確。步驟4:反饋您的測試結果,以便我們知道發生了什麼。 –