Skip to content

Instantly share code, notes, and snippets.

@kaz29
Created December 14, 2011 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaz29/1476089 to your computer and use it in GitHub Desktop.
Save kaz29/1476089 to your computer and use it in GitHub Desktop.
CakePHP Advent Calendar 2011/12/14
<?php
// @ operator
// compare to circle
$conditions = array(
'loc @' => array('circle' => array('point'=> array(10.1,10.1), 100)),
);
// order by distance
$order = array(
'loc <-> point(10.1,10.1)'
);
$result = $model->find('all', array('conditions'=>$conditions, 'order'=>$order));
<?php
class PostgresGeoFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'PostgresGeo'
*/
public $name = 'PostgresGeo';
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'loc' => array('type' => 'point', 'null' => false),
'rect' => array('type' => 'box', 'null' => false),
);
}
<?php
$data = array(
'loc' => array(10.1,10.1),
'rect' => array(array(10.1,10.2), array(100.1,100.2)),
);
$Model->create();
$Model->set($data);
$result = $Model->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment