Symfony2 自定义 Twig 扩展 - Class 未找到

Symfony2 custom Twig Extension - Class not found

我在添加 Twig 扩展时遇到问题。我收到以下错误:

ClassNotFoundException in appDevDebugProjectContainer.php line 317:
Attempted to load class "AppExtension" from namespace "HouseBundle\Twig".
Did you forget a "use" statement for another namespace?

我的代码:

/Users/Sites/www/houses/src/housesBundle/Twig/AppExtension.php

<?php

namespace HouseBundle\Twig;

class AppExtension extends \Twig_Extension
{

    public function getFilters()
    {
        return array(new \Twig_SimpleFilter('price', array($this, 'priceFilter')),
    );


    public function priceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
    {
        $price = number_format($number, $decimals, $decPoint, $thousandsSep);
        $price = '$'.$price;

        return $price;
    }

    public function getName()
    {
        return 'app_extension';
    }
}

/Users/Sites/www/houses/app/config/services.yml

services:
    app.twig_extension:
        class: HouseBundle\Twig\AppExtension
        tags:
            - { name: twig.extension }

如有任何帮助,我们将不胜感激。

给定此文件路径:

/Users/Sites/www/anildave/houses/src/housesBundle/Twig/AppExtension.php

您使用了错误的命名空间

namespace HouseBundle\Twig;

应该是

namespace housesBundle\Twig 

class: HouseBundle\Twig\AppExtension

应该是

class: housesBundle\Twig\AppExtension