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 to use ProductManger in contructor to do some stuff but it gives me this error
Catchable Fatal Error: Argument 1 passed to MyBundle\Controller\Test\ProductController::__construct() must be an instance of MyBundle\Services\ProductManager, instance of Symfony\Bundle\TwigBundle\Debug\TimedTwigEngine given, called in ..../app/cache/dev/appDevDebugProjectContainer.php on line 1202 and defined
I am new to symfony, any help is appreciated
ProductManager
as a service? You can access any service in aController
with$this->get('service_name')
. So no need to inject it. – ferdynator