2
我在添加樹枝擴展時遇到問題。我收到以下錯誤:Symfony2自定義樹枝擴展 - 未找到類
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';
}
}
/用戶/網站/ WWW /房屋/應用/配置/ services.yml
services:
app.twig_extension:
class: HouseBundle\Twig\AppExtension
tags:
- { name: twig.extension }
任何幫助將非常感激。
你有一個問題,你的類是剛剛結束後 'getFilters()' 方法(看 '}' 字符) – pbenard 2015-02-24 11:08:51
對不起,那是一個錯字。我糾正了它。 – 2015-02-24 11:14:31
您可能只需清除緩存。 – Broncha 2015-02-24 11:17:18