Hi all,
i have solved my problem by myself, but I am now once again facing another
problem-where you can possibly help me.
First of all, my code
*
EventsController.php*
*public function edit($id = null) {
$this->Event->id = $id;
if (!$this->Event->exists()) {
throw new NotFoundException('Ungültige Veranstaltung','error');
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Event->save($this->request->data)) {
$this->Session->setFlash('Die Veranstaltung wurde geändert !',
'success');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Die Veranstaltung konnte nicht
geändert werden','error');
}
} else {
$this->request->data = $this->Event->read(null, $id);
}
$variables = $this->Event->User->find('all',
array('conditions'=>array('User.typ'=> array('einsatzleiter',
'fahrdienstleiter'))));
$this->set(compact('variables'));
$ansprechpartner = $this->Event->Passanger->find('all',
array('conditions'=>array('Passanger.ansprechpartner'=> array('ja'))));
$this->set(compact('ansprechpartner'));
$events = $this->Event->find('all');
$this->set('events', $events);
$this->set('locations', $this->Event->Location->find('list'));
$places = $this->Event->Place->find('all');
$this->set(compact('places'));
}
public function data_interface($place_id) {
$locations = $this->Event->Location->findAllByPlaceId($place_id);
$this->set('locations', $locations);
}
public function save_data() {
if(!empty($this->data)) {
$this->Event->create($this->data);
if($this->Event->saveAll()) {
$this->Session->setFlash('Die Veranstaltung wurde geändert !',
'success');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Die Veranstaltung konnte nicht
gespeichert !','error');
}
$this->autoRender = false;
}
}*
*edit.ctp*
*<?php echo $this->Form->create('Event', array('type' =>
'file',array('controller'=>'events', 'action' => 'save_data')));?>
<?php echo $this->Form->input('id'); ?>
.....
<tr>
<th scope="row">Veranstaltungsort</th>
<td>
<?php
$select_value = array();
$select_value[null] = '-- Keine Auswahl --';
foreach($places as $place) {
$key = $place['Place']['id'];
$value = $place['Place']['stadt'];
$select_value[$key] = $value;
}
$mydata = $this->data;
if ( $mydata['Event']['place_id'] != null ) {
foreach ( $select_value as $k => $v ) {
if ( $mydata['Event']['place_id'] == $k ) {
$this_is_selected = $k;
}
}
} else {
$this_is_selected = 0;
}
echo $this->Js->Form->select('place_id', $select_value);
echo $this->Js->writeBuffer();
?>
</td>
</tr>
<tr>
<th scope="row">Locations</th>
<td>
<?php
echo $this->Html->div(null, '', array('id' => 'target-div'));
?>
</td>
</tr>
.....
<?php
echo $this->Js->submit('Speichern', array(
'url' => array(
'controller' => 'events',
'action' => 'save_data'
)));
echo $this->Js->writeBuffer();
echo $this->Form->end();
?>*
*data_interface.ctp*
*<?php
$select_value = array();
foreach($locations as $location) {
$key = $location['Location']['id'];
$value = $location['Location']['name'];
$select_value[$key] = $value;
}
echo $this->Form->select('location_id', $select_value, array('label'=>
false, 'multiple' => 'checkbox'));
?>*
The problem before I stand now is that I like to put the values that are
given to me as checkboxes from my ajax request also would like to save to
the events controller. Unfortunately, this does not work and cake saves me
no matter which checkbox i set, the value "1" to the database
.
Any ideas how I can solve this problem now?
Looking forward to help.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php