i have following tables
Events
Cities
Locations
EventLocations
When i edit an Event i can select the city (city_id) where the event is.
But every City has more than one location which i get over AJAX.
That works Great.
But now i want to store the locations which i have "checkboxed" into the table "event_locations"
How can i do that ?
Any ideas ?
Here is my Code:
edit.ctp
<?php
echo $this->Form->input('city_id');
echo $this->Js->writeBuffer();
?>
<div id="target-div"></div>
<script typ="text/javascript">
$("#EventCityId").click(function(){
var cityid = $("#EventCityId").val();
$.get("/events/fetch/"+ cityid,
function(data) {
$('#target-div').fadeOut("fast", function() {
$('#target-div').html(data);
$('#target-div').fadeIn("fast");
});
});
return false;
});
</script>
EventsController.php
public function fetch($city_id) {
$locations = $this->Event->Location->findAllByCityId($city_id);
$this->set('locations', $locations);
}
fetch.ctp
<?php
$select_value = array();
foreach($locations as $location) {
$key = $location['Location']['id'];
$value = $location['Location']['name'];
$select_value[$key] = $value;
}
$mydata = $this->data;
echo $this->Form->select('Location', $select_value, array('label'=> false, 'multiple' => 'checkbox'));
echo $this->Html->link(__('Add another Location'), array('controller' => 'locations', 'action' => 'add'));
?>
Thanks for help
-- Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment