mysql - 如何扩展 Doctrine 2 以处理 CodeIgniter 2 中的 MySQL 空间 ("point"字段类型)?

标签 mysql codeigniter orm doctrine geospatial

我正在使用 CodeIgniter 2 作为我的框架编写一个网站,并且我最近开始尝试将 Doctrine 2 用于 ORM。

我的数据库需要存储空间数据(例如,“点”类型的列),显然 Doctrine 无法开箱即用。

我在整个互联网上搜索过,只找到了这些提示:http://codeutopia.net/blog/2011/02/19/using-spatial-data-in-doctrine-2/

但是那篇文章并不清楚这些文件的保存位置以及还需要配置什么。我尝试联系作者,但从未收到回复。

有人可以帮忙吗?

谢谢! 瑞安

最佳答案

很久以前的事了,所以我忘记了一些细节,但是我把这 4 个文件放在一个名为 CodeIgniter/application/libraries/Doctrine/CustomAddon 的文件夹中:

  • 距离.php
  • 点.php
  • PointStr.php
  • PointType.php

我将每个的命名空间设置为“CustomAddon”。

然后在 CodeIgniter/application/libraries/Doctrine.php 的底部我放:

require_once APPPATH . 'libraries/Doctrine/CustomAddon/Distance.php';
require_once APPPATH . 'libraries/Doctrine/CustomAddon/Point.php';
require_once APPPATH . 'libraries/Doctrine/CustomAddon/PointStr.php';
require_once APPPATH . 'libraries/Doctrine/CustomAddon/PointType.php';
Doctrine\DBAL\Types\Type::addType('point', 'CustomAddon\PointType');
//Assuming $config is a Doctrine\ORM\Configuration object used to configure the EM
$config->addCustomNumericFunction('DISTANCE', 'CustomAddon\Distance');
$config->addCustomNumericFunction('POINT_STR', 'CustomAddon\PointStr');

// Create EntityManager
$this->em = EntityManager::create($connectionOptions, $config);

然后用法看起来像这样:

$point = new \CustomAddon\Point($geo['lat'], $geo['lon']);

关于mysql - 如何扩展 Doctrine 2 以处理 CodeIgniter 2 中的 MySQL 空间 ("point"字段类型)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5905986/

相关文章:

php - CodeIgniter:DB Insert 返回 '1' 但表中没有任何内容

php - 从纯 php 进行查询以查询 CodeIgniter

php - Grocery 加工: Display error message when updating database is failed

java - Hibernate + MySQL简单批量插入极慢

php - 在 MySQL 端或 PHP 端处理此查询更好吗?

java - 无法检索我希望使用存储过程选择的值

mysql - 如何在Entity中建立三个表之间的关系?

php - PHP (CodeIgniter) 文件下载中的空行

nhibernate - 如何在 NHibernate 中映射没有标识列的 View ?

java - 在 greenDAO 实体中添加数组作为属性