bonjour à toutes et à tous,
je cherche à trouver la différence en jours entre deux date en twig, et pour faire ceci j'ai suit la doc des extension en twig et j'ai procédé comme suite :

NafExtension.php
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
<?php
namespace NAF\CongeBundle\Twig;
 
class NafExtension extends \Twig_Extension
{
    public function getFunctions()
    {
        return array(
            'dateDiff' => new \Twig_Function_Method($this, 'dateDiff'),
        );
    }
 
    public function dateDiff($dateFin, $dateDebut)
    {
        $nbrJours = $dateFin->diff($dateDebut)->days;
 
        return $nbrJours;
    }
 
    public function getName()
    {
        return 'naf_extension';
    }
}
CongeBundleExtension.php
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
<?php
 
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 * Description of CongeBundleExtension
 *
 * @author Hp pavilion
 */
 
namespace NAF\CongeBundle\DependencyInjection;
 
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
 
class NafCongeBundleExtension extends Extension {
 
    public function load(array $configs, ContainerBuilder $container) {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);
 
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }
 
}
services.yml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
#services:
#    naf_conge.example:
#        class: NAF\CongeBundle\Example
#        arguments: [@service_id, "plain_value", %parameter%]
 
services:
    twig.naf_extension:
        class: NAF\CongeBundle\Twig\NafExtension
        tags:
            - { name: twig.extension }
et l'appel de la fonction
Code : Sélectionner tout - Visualiser dans une fenêtre à part
{{ dateDiff(entity.dateFin, entity.dateDebut) }}
ce code me donne cette erreur
The function "dateDiff" does not exist
je ne vois pas d'où viens l'erreur, merci de m'aider c'est vraiment urgent

Merciiiii