ClassNotFoundException: Attempted to load class “TwigExtension” from the global namespace

帅比萌擦擦* 提交于 2019-12-13 04:26:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!