问题
I'm trying to create a Twig Extension using the service container, but i'm getting a "ClassNotFoundException".
Here the exception:
ClassNotFoundException: Attempted to load class "TwigExtension" from the global namespace in \path\to\symfony-simple-blog\src\YagoQuinoy\SimpleBlogBundle\Twig\BlogExtension.php line 11. Did you forget a use statement for this class? Perhaps you need to add a use statement for one of the following: Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension
Here the code:
Twig extension:
namespace YagoQuinoy\SimpleBlogBundle\Twig;
/**
* Description of BlogExtension
*
* @author yagoquinoy@gmail.com
*/
class BlogExtension extends \TwigExtension
{
public function getFilters() {
return array(new \Twig_SimpleFilter('timeAgo', array($this, 'timeAgoFilter')));
}
public function timeAgoFilter() {
return 'yolo!';
}
public function getName() {
return 'blog_extension';
}
}
service.yml
services:
yago_quinoy_simple_blog.twig.blog_extension:
class: YagoQuinoy\SimpleBlogBundle\Twig\BlogExtension
tags:
- { name: twig.extension }
Edit: Solved.
smarber Twig_Extension not TwigExtension, symfony.com/doc/current/cookbook/templating/twig_extension.html
来源:https://stackoverflow.com/questions/27985614/classnotfoundexception-attempted-to-load-class-twigextension-from-the-global