2

我在添加 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 }

任何帮助将非常感激。

4

1 回答 1

2

鉴于此文件路径:

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

您使用了错误的命名空间

namespace HouseBundle\Twig;

应该

namespace housesBundle\Twig 

class: HouseBundle\Twig\AppExtension

应该

class: housesBundle\Twig\AppExtension
于 2015-02-24T11:22:53.950 回答