更新 2011-01-23
新規 2009-08-23
Google Map の地図を入れた住所録(symfony の CRUD)のサンプル (その2)
================================================================================
住所録のリスト部分に GoogleMap を表示しています。
■schema.yml (一部)
---
:
address:
_attributes: { phpName: Address }
id:
name: varchar(50)
address: longvarchar
email: longvarchar
comment: longvarchar
created_at:
:
---
■action.class.php
---
forward('admin', 'list');
}
public function executeList()
{
$c = new Criteria();
$c->addAscendingOrderByColumn(AddressPeer::ID);
$this->addresss = AddressPeer::doSelect($c);
if (count($this->addresss) == 0) {
return;
}
$this->address = $this->addresss[0];
$id = $this->getRequestParameter("id");
if ($id != null) {
$this->address = AddressPeer::retrieveByPk($id);
}
$this->geocoding = $this->getGeocoding($this->address);
}
public function executeShow()
{
$this->address = AddressPeer::retrieveByPk($this->getRequestParameter('id'));
$this->forward404Unless($this->address);
$this->addresss = array($this->address);
$this->geocoding = $this->getGeocoding($this->address);
// $this->getRequest()->setAttribute("id", $this->getRequestParameter('id'));
}
private function getGeocoding($address) {
$url = "http://www.geocoding.jp/api/?q={$address->getAddress()}";
$geocoding = simplexml_load_file($url);
$this->forward404Unless($geocoding);
$this->forward404If(isset($geocoding->error));
return $geocoding;
}
public function executeCreate()
{
$this->address = new Address();
$this->addresss = array();
$this->setTemplate('edit');
}
public function executeEdit()
{
$this->address = AddressPeer::retrieveByPk($this->getRequestParameter('id'));
$this->forward404Unless($this->address);
$this->addresss = array($this->address);
$this->geocoding = $this->getGeocoding($this->address);
}
public function executeUpdate()
{
if (!$this->getRequestParameter('id'))
{
$address = new Address();
}
else
{
$address = AddressPeer::retrieveByPk($this->getRequestParameter('id'));
$this->forward404Unless($address);
}
$address->setId($this->getRequestParameter('id'));
$address->setName($this->getRequestParameter('name'));
$address->setAddress($this->getRequestParameter('address'));
$address->setEmail($this->getRequestParameter('email'));
$address->setComment($this->getRequestParameter('comment'));
$address->save();
return $this->redirect('admin/show?id='.$address->getId());
}
public function executeDelete()
{
$address = AddressPeer::retrieveByPk($this->getRequestParameter('id'));
$this->forward404Unless($address);
$address->delete();
return $this->redirect('admin/list');
}
}
---
■layout.php
---
getRaw('sf_content') ?>
---
■listSuccess.php
---
リスト
ID, 名前をクリックすると、詳細が表示されます。
住所をクリックすると、その住所の地図が表示されます。
ID |
名前 |
住所 |
getId(), 'admin/show?id='.$address->getId()) ?> |
getName(), 'admin/show?id='.$address->getId()) ?> |
getAddress() ?> |
|
|
---
■showSuccess.php
---
ID: |
getId() ?> |
名前: |
getName() ?> |
住所: |
getAddress() ?> |
Email: |
getEmail() ?> |
コメント: |
getComment() ?> |
登録日: |
getCreatedAt() ?> |
|
|
getId()) ?>
getId()) ?>
---
■editSuccess.php
---
名前: |
50,
)) ?> |
住所: |
'30x3',
)) ?> |
Email: |
'30x3',
)) ?> |
コメント: |
'30x3',
)) ?> |
getId()): ?>
getId(), 'post=true&confirm=Are you sure?') ?>
getId()) ?>
---
以上