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:反馈您的测试结果,以便我们知道发生了什么。 –