php - symfony申明服务,把Controller放在app/utils下申请命名空间调用服务报命名空间错误
怪我咯
怪我咯 2017-04-11 09:41:03
0
1
165

<?php

namespace Utils;

use SymfonyComponentDependencyInjectionContainerInterface;

class Sessions
{

private $container;
private $session;

public function __construct(ContainerInterface $container)
{
    $this->container = $container;
    $this->session = $this->container->get('session');
}

在控制器使用$this->get('utils.sessions');提示
Attempted to load class "Sessions" from namespace "Utils".
Did you forget a "use" statement for another namespace?
命名空间具体怎么弄,放在Bundle中申明就没有这个错误,还是命名空间的问题,具体还没找到解决方案

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
左手右手慢动作

能提供具体你的文件的结构是什么杨的吗?

其实主要问题如果你想把你的PHP文件放到其他文件夹, 你需要在composer.json的文件里面声明路径,然后再update

比如说:

"autoload": {
    "psr-4": {
        "Test\\": "Test/src"
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!