Bonjour a tous,

je suis confronté a un petit problème depuis quelques jour.

Je travail sur la dernière version de symfony2 , avec l'environnement netbean.

Je souhaiterais utilisé une procédure stockées MySQL directement dans une requette.

Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
select * from lieu l
where get_distance_m( l.log, l.lat , ma_long, ma_lat ) ;

j'ai ensuite vu que sur symfony il fallait "enregistrer la procédure dans doctrine "

Fichier config :

    orm:
        entity_managers:
            default :
                dql : 
                    numeric_functions  :
                        get_distance_m :MonAppli\WebBundle\Dql\Evenement\Get_Distance_m
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true
Fichier fonctionnode :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
 
/**
 * Custom DQL function
 * Retourne la distanc entre deux point grace a leur coordonées géographiques
 * 
 * usage Get_distance_m(latA,lgtA,latB,lgtB)
 */
 
class Get_distance_m extends FunctionNode
{
    /**
     * @var float
     */
    public $latA;
 
    /**
     * @var float
     */
    public $lgtA;
    /**
     * @var float
     */
    public $latB;
 
    /**
     * @var float
     */
    public $lgtB;
 
    public function parse(\Doctrine\ORM\Query\Parser $parser)
    {
        var_dump($parser);
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
        $this->latA = $parser->ArithmeticPrimary();       
        $parser->match(Lexer::T_COMMA);
        $this->lgtA = $parser->ArithmeticPrimary();   
        $parser->match(Lexer::T_COMMA);
        $this->latB = $parser->ArithmeticPrimary();       
        $parser->match(Lexer::T_COMMA);
        $this->lgtB = $parser->ArithmeticPrimary();
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }
 
    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
    {
        return 'Get_Distance_m(' .
            $this->latA->dispatch($sqlWalker) . ', ' .
            $this->lgtA->dispatch($sqlWalker) . ', ' . 
            $this->latB->dispatch($sqlWalker) . ', ' . 
            $this->lgtB->dispatch($sqlWalker) . 
        ')'; 
    }
}
le controller
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    /**
     * Fonction de recherche d'évenement 
     * par date et 
     */
    public function RechEvenementDateLieuAction() {
        $data = $this->getRequest()->request->all();
        //$lgt = $data['lgt'];
        //$lat = $data['lat'];
        $datedeb = $data['datedeb'];
        $datefin = $data['datefin'];
        $lgt = 166.45799999999997 ;
        $lat = -22.2758 ;
        $repository = $this->getDoctrine()
                ->getManager()
                ->getRepository('MonApplibundle:Evenement');
 
        $entities = $repository->GetByRechDateLieu($datedeb,$datefin,$lgt,$lat,30000);
        var_dump($entities);
        //return $this->render('NuwlandWebBundle:Evenement:recheven.html.twig', array(
               //     'entities' => $entities));
    }
et le repository

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
    public function GetByRechDateLieu($dateDeb,$dateFin,$lgt,$lat,$maxDistM){
        $qb =  $this->getEntityManager()->createQueryBuilder() ;
        $qb->select('p')
           ->from('NuwlandWebBundle:Evenement','p')
           ->leftJoin('p.evenLieu', 'l')
           ->where("p.evenDatedebut =$dateDeb")
           ->andWhere("p.evenDatefin =$dateFin")
           ->andWhere("Get_Distance_m(l.lat,l.longt,$lat,$lgt) < $maxDistM")
           ->orderBy('p.evenTitre','ASC') ;
        return $qb->getQuery()->getResult();
    }
perso je pense q'uil plante a la lecture du fichier config.

voila l'erreur
( ! ) Fatal error: Uncaught exception 'Symfony\Component\Config\Definition\Exception\InvalidTypeException' with message 'Invalid type for path "doctrine.orm.entity_managers.default.dql.numeric_functions". Expected array, but got string' in C:\wamp\www\Nuwland\vendor\symfony\symfony\src\Symfony\Component\Config\Definition\ArrayNode.php on line 277
( ! ) Symfony\Component\Config\Definition\Exception\InvalidTypeException: Invalid type for path "doctrine.orm.entity_managers.default.dql.numeric_functions". Expected array, but got string in C:\wamp\www\Nuwland\vendor\symfony\symfony\src\Symfony\Component\Config\Definition\ArrayNode.php on line 277
et la pile d'appel.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#	Time	Memory	Function	Location
1	0.0006	252616	{main}( )	..\app.php:0
2	0.0217	1751032	Symfony\Component\HttpKernel\Kernel->handle( )	..\app.php:23
3	0.0217	1751216	Symfony\Component\HttpKernel\Kernel->boot( )	..\bootstrap.php.cache:2246
4	0.0887	4478168	Symfony\Component\HttpKernel\Kernel->initializeContainer( )	..\bootstrap.php.cache:2215
5	0.3087	8508744	Symfony\Component\DependencyInjection\ContainerBuilder->compile( )	..\bootstrap.php.cache:2435
6	0.3299	8536472	Symfony\Component\DependencyInjection\Compiler\Compiler->compile( )	..\ContainerBuilder.php:623
7	0.3299	8542312	Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass->process( )	..\Compiler.php:119
8	0.3302	8545032	Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass->process( )	..\MergeExtensionConfigurationPass.php:39
9	0.8492	14558296	Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension->load( )	..\MergeExtensionConfigurationPass.php:50
10	0.8516	14741936	Symfony\Component\DependencyInjection\Extension\Extension->processConfiguration( )	..\DoctrineExtension.php:44
11	0.8516	14742072	Symfony\Component\Config\Definition\Processor->processConfiguration( )	..\Extension.php:107
12	0.8668	15259296	Symfony\Component\Config\Definition\Processor->process( )	..\Processor.php:50
13	0.8668	15259712	Symfony\Component\Config\Definition\BaseNode->normalize( )	..\Processor.php:33
14	0.8669	15259712	Symfony\Component\Config\Definition\ArrayNode->normalizeValue( )	..\BaseNode.php:268
15	0.8673	15262352	Symfony\Component\Config\Definition\BaseNode->normalize( )	..\ArrayNode.php:308
16	0.8673	15262464	Symfony\Component\Config\Definition\ArrayNode->normalizeValue( )	..\BaseNode.php:268
17	0.8674	15263264	Symfony\Component\Config\Definition\BaseNode->normalize( )	..\ArrayNode.php:308
18	0.8674	15263264	Symfony\Component\Config\Definition\PrototypedArrayNode->normalizeValue( )	..\BaseNode.php:268
19	0.8674	15263816	Symfony\Component\Config\Definition\BaseNode->normalize( )	..\PrototypedArrayNode.php:283
20	0.8674	15263816	Symfony\Component\Config\Definition\ArrayNode->normalizeValue( )	..\BaseNode.php:268
21	0.8674	15264024	Symfony\Component\Config\Definition\BaseNode->normalize( )	..\ArrayNode.php:308
22	0.8675	15264024	Symfony\Component\Config\Definition\ArrayNode->normalizeValue( )	..\BaseNode.php:268
23	0.8675	15264240	Symfony\Component\Config\Definition\BaseNode->normalize( )	..\ArrayNode.php:308
24	0.8675	15264240	Symfony\Component\Config\Definition\ArrayNode->validateType( )	..\BaseNode.php:265
En attente de votre retour.
Merci d'avance