Created
May 3, 2017 21:53
-
-
Save smzn/3d31473f8fda11dfe1ec2b39a3563574 to your computer and use it in GitHub Desktop.
import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function import(){ | |
if($this->request->is('post')){ | |
$up_file = $this->data['School']['XmlFile']['tmp_name']; | |
$fileName = 'post.xml'; | |
if(is_uploaded_file($up_file)){ | |
move_uploaded_file($up_file, $fileName); | |
$xmlArray = Xml::toArray(Xml::build($fileName)); | |
$i = 0; | |
foreach($xmlArray['Dataset']['ksj:School'] as $line){ | |
$latlng = explode(" ",$xmlArray['Dataset']['gml:Point'][$i++]['gml:pos']); | |
$data = array( | |
'name' => $line['ksj:name'], | |
'address' => $line['ksj:address'], | |
'region_id' => str_pad($line['ksj:administrativeArea']['@'],5,'0',STR_PAD_LEFT), | |
'category_id' => $line['ksj:type'], | |
'latitude' => $latlng[0], | |
'longitude' => $latlng[1] | |
); | |
$this->School->create($data); | |
$this->School->save(); | |
} | |
} | |
} | |
$this->redirect(array('action'=>'index')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment