我正在使用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"
但如果我把它放在doctrine.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
谢谢。答案 0 :(得分:3)
我解决了我的问题,似乎我正在混合短语和完整语法,这是我的整个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
答案 1 :(得分:0)
这可能是您的配置文件存在问题,而且您的间距可能不正确。要特别注意确保所有的缩进都是正确的,并且dql在orm之后缩进,并且orm与dbal对齐。