我正在使用 https://github.com/djlambert/doctrine2-spatial 并且在尝试使用“包含”函数进行查询时出现错误
首先,如果我把这个:
dql:
numeric_functions:
Contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains
在 doc ( https://github.com/djlambert/doctrine2-spatial/blob/master/INSTALL.md ) 中的 orm 下,我有这个错误:
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
Unrecognized options "dql" under "doctrine.orm"
但是如果我把它放在 Dotct.orm.entity_managers.default 下没有错误但我在运行查询时仍然有错误,这是我的代码:
$sql = 'SELECT DemoTadBundle:DeliveryZone dz WHERE Contains(dz.area, :point)'; //dz.area is of type polygon
$converter = new SpatialConverter();
$q = $this->_em->createQuery($sql)->setParameter('point', $converter->convertToDatabaseValue($address->getPoint())); //$address->getPoint returns an CrEOF\Spatial\PHP\Types\Geometry\Point object
return $q->getOneOrNullResult();
这是错误:
[Semantical Error] line 0, col 41 near 'Contains(dz.area,': Error: Class 'Contains' is not defined.
有人可以帮我解决这个问题吗?
我的 symfony 版本是 2.5
谢谢你。
最佳答案
我解决了我的问题,似乎我混合了简短和完整的语法,这是我的整个 config.yml 文件(只有学说部分)
我希望这个能帮上忙 :)
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
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
orm:
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
default:
dql:
numeric_functions:
Contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains
AsText: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\AsText
AsBinary: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\AsBinary
GeomFromText: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeomFromText
auto_mapping: true
mappings:
gedmo_tree:
type: annotation
prefix: Gedmo\Tree\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
alias: GedmoTree # this one is optional and will default to the name set for the mapping
is_bundle: false
关于Symfony2/Doctrine2-spatial : Class 'Contains' is not defined,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24456025/