我正在使用 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/