I have 4 tables.
properties, characteristics, characteristics_properties, characteristic_translations.
Properties HABTM characteristics and Vice Versa.
Also characteristics has many characteristic_translation and characteristic_translation belongs to characteristic so to give a more clear example here is the tables diagram:
So what I need is that when I create a property to display a list of characteristics:
characteristic_name_1 (icon1) [] checkbox1
characteristic_name_2 (icon2) [] checkbox2
characteristic_name_3 (icon3) [] checkbox3
So in the add view I have:
<?php
echo $this->Form->create('Property', array(class'=>'form-horizontal'));
echo $this->Form->input('title', array('class'=>'form-control property-select'));
echo $this->Form->input('Characteristic', array('type'=>'select', 'multiple'=>'checkbox','options' => $characteristics,'selected' => $this->Html->value('Characteristic.Characteristic')));
echo $this->Form->end();
?>
The property Controller is:
/**
* add method
*
* @return void
*/
public function add() {
if ($this->request->is('post')) {
//debug($this->request->data);
$this->Property->create();
$this->request->data['Property']['user_id'] = $this->Auth->user('id');
if ($this->Property->save($this->request->data)) {
$this->Session->setFlash(__('The property has been saved.'),'flash_success');
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The property could not be saved. Please, try again.'),'flash_error');
}
}
$users = $this->Property->User->find('list');
$currencies = $this->Property->Currency->find('list');
$roomTypes = $this->Property->RoomType->find('list', array('conditions' => array('RoomType.language_id'=>2), 'recursive'=>-1));
$accommodationTypes = $this->Property->AccommodationType->find('list', array('conditions' => array('AccommodationType.language_id'=>2), 'recursive'=>-1));
$houseAvailabilities = $this->Property->HouseAvailability->find('list', array('conditions' => array('HouseAvailability.language_id'=>2), 'recursive'=>-1));
$deleteReasons = $this->Property->DeleteReason->find('list', array('conditions' => array('DeleteReason.language_id'=>2), 'recursive'=>-1));
$characteristics = $this->Property->Characteristic->find('list');
$extras = $this->Property->Extra->find('list');
$safeties = $this->Property->Safety->find('list');
$services = $this->Property->Service->find('list');
$this->set(compact('users', 'currencies', 'roomTypes', 'accommodationTypes', 'houseAvailabilities', 'deleteReasons', 'characteristics', 'extras', 'safeties', 'services'));
}