FatalErrorException: Error: Call to a member function has() on a non-object

后端 未结 3 1720
感情败类
感情败类 2020-12-16 05:01

I have a read a lot of topics on this and I can\'t seem to find a solution to my problem.

I feel like the problem is obvious and maybe I have just been staring at

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 05:37

    The problem is the container not being injected into the controller here.

    Normally, Symfony does this automatically if you're extending Symfony\Bundle\FrameworkBundle\Controller\Controller, which itself extends Symfony\Component\DependencyInjection\ContainerAware:

    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    
    class YourController extends Controller
    

    The container is injected into the controller (if not explicitly defined as a service) using setter injection calling the method setContainer() with the container as an argument.

    Now, as you configured your controller as a service you need to add the setContainer call to your service configuration:

    services:
        database_controller:
            class:  Fuel\FormBundle\Controller\DatabaseController
            calls:
                - [setContainer, ["@service_container"]]
    

    Clear your cache afterwards.

提交回复
热议问题