部署Symfony2应用程序后,“无法导入资源”异常

时间:2013-04-11 18:15:58

标签: symfony

在服务器上部署我的Symfony应用程序后,我使用命令删除缓存:

sudo rm -rf app/cache

通常一切正常,但我不时会收到一条消息:

Cannot import resource
"/var/projectsssssss/src/Project/UserPanelBundle/Controller" from 
"/var/projectsssssss/src/Project/UserPanelBundle/Resources/config/routing.yml".

然后,我再次删除缓存,它一直工作,直到随机下一次部署。我为Routes使用注释。使用Controller generateUrl方法时抛出异常这里是堆栈跟踪:

#0 /var/project/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php(75): Symfony\\Component\\Config\\Loader\\FileLoader->import('@UserPanelBundl...', 'annotation', false, '/var/projectsss...')
#1 /var/project/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php(75): Symfony\\Component\\Routing\\Loader\\YamlFileLoader->load('/var/projectsss...', NULL)
#2 /var/project/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php(75): Symfony\\Component\\Config\\Loader\\FileLoader->import('@UserPanelBundl...', NULL, false, '/var/projectsss...')
#3 /var/project/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/DelegatingLoader.php(52): Symfony\\Component\\Routing\\Loader\\YamlFileLoader->load('/var/projectsss...', NULL)
#4 /var/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php(57): Symfony\\Component\\Config\\Loader\\DelegatingLoader->load('/var/projectsss...', NULL)
#5 /var/project/app/cache/main/classes.php(1742): Symfony\\Bundle\\FrameworkBundle\\Routing\\DelegatingLoader->load('/var/projectsss...', NULL)
#6 /var/project/app/cache/main/classes.php(1451): Symfony\\Bundle\\FrameworkBundle\\Routing\\Router->getRouteCollection()
#7 /var/project/app/cache/main/classes.php(1400): Symfony\\Component\\Routing\\Router->getGenerator()
#8 /var/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php(45): Symfony\\Component\\Routing\\Router->generate('userpanel_apps', Array, false)
#9 /var/project/src/Project/UserPanelBundle/Controller/AppsController.php(26): Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller->generateUrl('userpanel_apps', Array)
#10 [internal function]: Project\\UserPanelBundle\\Controller\\AppsController->indexAction()
#11 /var/project/app/bootstrap.php.cache(1426): call_user_func_array(Array, Array)
#12 /var/project/app/bootstrap.php.cache(1390): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)
#13 /var/project/app/bootstrap.php.cache(1566): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)
#14 /var/project/app/bootstrap.php.cache(617): Symfony\\Bundle\\FrameworkBundle\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)
#15 /var/project/web/app.php(28): Symfony\\Component\\HttpKernel\\Kernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))
#16 {main}

我认为缓存生成存在一些问题,但如何避免呢?

修改

我的routing.yml

default:
    resource: "@UserPanelBundle/Controller"
    type:     annotation

2 个答案:

答案 0 :(得分:1)

好的,我发现了问题所在。其中一个控制器类名称没有Controller后缀。 @catchamonkey看起来你是对的:)。

答案 1 :(得分:0)

您实际上删除了缓存文件夹

sudo rm -rf app / cache

应该是

sudo rm -fr app / cache / *

请尝试使用php app / console进行更好的事情。您甚至不必使用sudo

另一个你需要重新创建文件夹并给出

sudo setfacl -R -m u:www-data:rwX -m u:whoami:rwX app / cache app / logs

sudo setfacl -dR -m u:www-data:rwx -m u:whoami:rwx app / cache app / logs

www可能会根据您的apache / nginx /其他网络服务器用户名

而改变