I'm buiding an application on symfony2 and need a new twig filter :
I created a folder Twig in my bundle and created there this file AppExtension.php :
namespace App\MyBundle\Twig;
use Twig_Extension;
use Twig_Filter_Method;
class AppExtension extends \Twig_Extension
{
public function getFilters()
{
return array(
'left' => new \Twig_Filter_Method($this, 'leftFilter'),
);
}
public function leftFilter($string, $start = 0, $length = 1)
{
$left = substr($string, $start, $length);
return $left;
}
public function getName()
{
return 'app_extension';
}
}
and then I declared it in services.yml :
app.twig.app_extension:
class: App\MyBundle\Twig\AppExtension
tags:
- { name: twig.extension }
But I get this RuntimeException:
The autoloader expected class "App\MyBundle\Twig\AppExtension" to be defined in file ".../src/\App\MyBundle\Twig\AppExtension.php". The file was found but the class was not in it, the class name or namespace probably has a typo.
Can someone please tell me what I missed here ?
namespace
(corrected while posting)? You can also try clearing symfony's cache and APC cache if you have. – Touki