Hallo Zusammen,
Ich möchte beim abschicken eines Formulars im Backend die Geokoordinaten einer Adresse in meine Datenbank eintragen.
So gehe ich bisher vor:
DCA:
PHP-Code:
// Config
'config' => array
(
'dataContainer' => 'Table',
'enableVersioning' => true,
'onsubmit_callback' => array(array('tl_qfOM_generateLatLong', 'generateLatLong')),
'sql' => array
(
'keys' => array
(
'id' => 'primary',
'published' => 'index'
)
),
),
PHP-Code:
class tl_qfOM_generateLatLong extends Backend
{
public function generateLatLong($varValue, DataContainer $dc)
{
// Get lat and long by address
$address = $this->Input->post('lage_strasse')." ".$this->Input->post('lage_hausnummer').", ".$this->Input->post('lage_stadt');
$prepAddr = str_replace(' ','+',$address);
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
/// Update the database
$thisID = $this->Session->get('CURRENT');
$thisID = $thisID['IDS'][0];
$this->Database->prepare("
UPDATE tl_qfOM_objekte
SET
lage_lat='". $lat."',
lage_long='".$long."'
WHERE id=?
")
->execute($thisID);
}
}
Leider aktualisiert er mir die Datenbank nicht - der Google-Jason ist aber einwandfrei.
Wo muss ich ansetzten, gibt es alternativen zu onsubmit_callback?
save_callback habe ich versucht -> jedoch wurde mir dann entweder lage_lat oder lage_long in der Datenbank aktualisiert, nie beide gleichzeitig.
Vielen Dank!
Lesezeichen