所以我已经完成了 Symfony 3 的新安装,尝试设置一些 API 路由,但我无法访问控制器内的容器。
ContainerAwareTrait
我的控制器从具有$this->container->get('service')
.
"message": "Call to a member function get() on null",
"class": "Component\\Debug\\Exception\\FatalThrowableError",
"trace": [{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "src\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller.php",
"line": 50,
"args": []
}]
看起来 symfony 自己的控制器无法找到容器,我缺少什么吗?
这是控制器的代码:
use FOS\RestBundle\Controller\Annotations\Get;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
class UsersController extends Controller
{
/**
* @Get()
*
* @return JsonResponse
*/
public function getUsersAction()
{
$users= $this->get('doctrine.orm.entity_manager')->getRepository('AppBundle:User')->findAll();
return new JsonResponse($users, 200):
}
}