我在添加 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 }
任何帮助将非常感激。