4

我正在使用https://github.com/djlambert/doctrine2-spatial尝试使用“包含”功能进行查询时出错

首先,如果我把这个:

dql:
    numeric_functions:
       Contains:     CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains

在文档中的 orm 下(https://github.com/djlambert/doctrine2-spatial/blob/master/INSTALL.md),我有这个错误:

[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
Unrecognized options "dql" under "doctrine.orm"

但如果我把它放在教义.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

谢谢你。

4

2 回答 2

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
于 2014-10-15T09:38:05.320 回答
0

这可能是您的配置文件的问题,并且您的间距可能不正确。非常注意确保所有缩进都是正确的,并且 dql 在 orm 之后缩进,并且 orm 与 dbal 对齐。

于 2014-06-27T19:52:03.493 回答