【发布时间】:2019-04-14 20:08:32
【问题描述】:
我正在使用 Symfony 4 和 Doctrine2-Spatial。文档configuration guide 说:
将你需要的类型和函数添加到你的 Symfony 配置文件中。教义类型名称不是硬编码的。”
还有一个例子:
doctrine:
dbal:
types:
geometry: CrEOF\Spatial\DBAL\Types\GeometryType
point: CrEOF\Spatial\DBAL\Types\Geometry\PointType
polygon: CrEOF\Spatial\DBAL\Types\Geometry\PolygonType
linestring: CrEOF\Spatial\DBAL\Types\Geometry\LineStringType
我需要使用MultiLineString类型,但是CrEOF\Spatial\DBAL\Types\Geometry\目录下没有这样的类型类。我已将 MultiLineStringType(LineStringType 类的副本)添加到我的 App\Doctrine 目录中,并在学说配置中添加了一行,如下所示:
multilinestring: App\Doctrine\MultiLineStringType
然后在我的控制器中执行以下操作:
$parser = new \CrEOF\Geo\WKT\Parser($multilinestring);
$geo = $parser->parse();
$path = new \CrEOF\Spatial\PHP\Types\Geometry\MultiLineString($geo['value']);
$route->setPath($path); // The multilinestring field type
但是当我坚持我的学说实体时,我得到了一个例外
几何列值必须实现 GeometryInterface
请帮助我。我究竟做错了什么?文档很差...
UPD:如果我通过本机 SQL 查询这样放置多行字符串数据:
UPDATE Routes SET Path=PolyFromText(MULTILINESTRING (....)) WHERE Id=1
然后通过 ORM $entity->getPath() 获取数据我得到了一个普通的CrEOF\Spatial\PHP\Types\Geometry\MultiLineString 对象。所以我想问题出在我试图设置 MultiLineString 对象的控制器中。
【问题讨论】:
标签: symfony doctrine-orm doctrine