Dabei nochmal vielen Dank an euromark
Vorerst das Datenmodell:
Es geht in diesem Tutorial nur um die Beziehung zwischen 'clients' und 'progresses' (und die Tabellen die da noch dahinter hängen).
Die 1:1-Beziehung zwischen 'clients' und 'progresses'
Die Models:
Client: hasOne = array('Progress');
Progress: belongsTo = array('Client');
Die Action (ClientsController/add):
- Code: Alles auswählen
function add() {
if (!empty($this->data)) {
$this->Client->create();
if ($this->Client->save($this->data)) {
$this->data['Progress']['client_id'] = $this->Client->id;
$this->data['Progress']['employee_id'] = $this->data['Progress']['Employee']['name'];
$this->data['Progress']['kind_id'] = $this->data['Progress']['Kind']['kind'];
$this->Client->Progress->save($this->data);
$this->Session->setFlash('Der Klient wurde angelegt.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Der Klient konnte nicht angelegt werden.');
}
}
...
$this->set('progresses', $this->Client->Progress->find('list', array('fields' => 'date')));
$this->set('employees', $this->Client->Progress->Employee->find('list'));
$this->set('kinds', $this->Client->Progress->Kind->find('list', array('fields' => 'kind')));
}
Hier habe ich einige Aufrufe von set() weggelassen für die ganzen anderen Beziehungen.
Aber wie gesagt, geht es hier nur um die 1:1-Beziehungen.
View (add.ctp) - nur Auszug:
- Code: Alles auswählen
...
echo $html->tag('div', null, array('id' => 'tabs'));
$fields = $processes->fields();
$i = 0;
foreach ($fields as $field) {
$field['options']['id'] = "$i";
echo $form->input($field['field_name'], $field['options']);
$i++;
}
echo $html->tag('/div') . "\n";
...
Und dann noch der Helper (processes.php):
- Code: Alles auswählen
<?php
class ProcessesHelper extends AppHelper {
function fields() {
$fields = array(
$employees = array(
'field_name' => 'Progress.Employee.name',
'options' => array(
'label' => 'Mitarbeiter'
)
),
$previous_employees = array(
'field_name' => 'Progress.previous_employees',
'options' => array(
'label' => 'bearbeitet von'
)
),
$date_of_meeting = array(
'field_name' => 'Progress.date',
'options' => array(
'label' => 'Datum',
'dateFormat' => 'DMY'
)
),
$kind = array(
'field_name' => 'Progress.Kind.kind',
'options' => array(
'label' => 'Art des Gesprächs'
)
),
$previous_kinds = array(
'field_name' => 'Progress.previous_kinds',
'options' => array(
'label' => 'vorherige Arten'
)
),
$location = array(
'field_name' => 'Progress.location',
'options' => array(
'label' => 'Ort'
)
),
$previous_locations = array(
'field_name' => 'Progress.previous_locations',
'options' => array(
'label' => 'vorherige Orte'
)
),
$duration = array(
'field_name' => 'Progress.duration',
'options' => array(
'label' => 'Dauer'
)
),
$total = array(
'field_name' => 'Progress.total_duration',
'options' => array(
'label' => 'gesamte Dauer'
)
),
$topic = array(
'field_name' => 'Progress.topic',
'options' => array(
'label' => 'Thema'
)
),
$further_informations = array(
'field_name' => 'Progress.further_information',
'options' => array(
'label' => 'weitere Informationen'
)
),
$action = array(
'field_name' => 'Progress.action',
'options' => array(
'label' => 'Maßnahme'
)
),
$previous_actions = array(
'field_name' => 'Progress.previous_actions',
'options' => array(
'label' => 'bereits getroffene Maßnahmen'
)
)
);
return $fields;
}
}
?>
So damit sollte es dann funktionieren.

