php - Argument 1 passed to __construct must be an instance of Services\ProductManager, none given -
in service.yml
test_product.controller: class: mybundle\controller\test\productcontroller arguments: ["@product_manager.service"]
in controller
class productcontroller extends controller { /** * @var productmanager */ private $productmanager; public function __construct(productmanager $productmanager){ $this->productmanager = $productmanager; } }
in routing.yml
test_product_addnew: path: /test/product/addnew defaults: { _controller:test_product.controller:addnewaction }
i want use productmanger in contructor stuff gives me error
catchable fatal error: argument 1 passed mybundle\controller\test\productcontroller::__construct() must instance of mybundle\services\productmanager, instance of symfony\bundle\twigbundle\debug\timedtwigengine given, called in ..../app/cache/dev/appdevdebugprojectcontainer.php on line 1202 , defined
i new symfony, appreciated
you have inverted logical of services.
first, it's manager wich must defined service because it's need call controller.
// services.yml product_manager: class: mybundle\path\to\productmanager
then call directly manager defined service in controller.
// controller class productcontroller extends controller { [...] $this->get('product_manager'); [...] }
and not need overload __construct() methode. call ->get(any_service)
need it.
also route wrong. have define controller namespace.
// routing.yml test_product_addnew: path: /test/product/addnew defaults: { _controller:mybundle:product:addnew }
Comments
Post a Comment