<?php

class PostalController extends AppController {
	public $name = 'Postal';
	public $uses = null;
	public $layout = null;
	
	function postal(){
		// GETパラメータを取得
		$arg = $this->params["url"]["c"];

		// GETパラメータが存在するときのみ処理
		if($arg !== ""){
			$file = '../webroot/data/postal.xml';
			
			// XML読み込み
			$xml = simplexml_load_file($file);
			
			// XPATHで郵便番号とマッチする住所データの読み込み
			$add1 = $xml->xpath("address[postalcode = " . $arg . "]/address1");
			$add2 = $xml->xpath("address[postalcode = " . $arg . "]/address2");
			$add3 = $xml->xpath("address[postalcode = " . $arg . "]/address3");

			// 住所をViewに表示
			$this->data['postalAddress1'] = $add1[0][0];
			$this->data['postalAddress2'] = $add2[0][0];
			$this->data['postalAddress3'] = $add3[0][0];
		}
	}
}

?>