loops - Match data entered with data in the database CAKEPHP -
i stuck @ loop function of cakephp. logic need compare data entered users data in table. have 2 tables, 1 bookings
, 1 inventories_bookings
. below coding doesnot work. help! thanks
public function add2() { if ($this->request->is('post')) { foreach ($invbook $invenbook) { if ($this->request->data['booking']['bookings_location'] == $invenbook['inventoriesbooking']['test']) { $this->session->setflash(__('the booking cannot 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')); } }
i use custom validation function this.
you able create own functions in model, , here can access database lookup. if matches can return true.
you can read custom validation methods in book.
there example of rule using db in book. quoted great justice.
class user extends appmodel { public $validate = array( 'promotion_code' => array( 'rule' => array('limitduplicates', 25), 'message' => 'this code has been used many times.' ) ); public function limitduplicates($check, $limit) { // $check have value: array('promotion_code' => 'some-value') // $limit have value: 25 $existing_promo_count = $this->find('count', array( 'conditions' => $check, 'recursive' => -1 )); return $existing_promo_count < $limit; } }
Comments
Post a Comment