Answer the question
In order to leave comments, you need to log in
symfony2. How to properly use a repository in a controller?
Hello dear experts. Please tell me what I'm doing wrong and how to overcome this error:
Catchable Fatal Error: Argument 1 passed to Allergo\MainBundle\Controller\HomePageController::__construct() must be an instance of Allergo\MainBundle\Entity\CategoryRepository, none given, called in /var/www/allergo.loc/app/cache/dev/classes.php on line 2456 and defined
services:
allergo_main.home_page_controller:
class: Allergo\MainBundle\Controller\HomePageController
arguments: [ @repository.category ]
services:
repository.category:
class: Allergo\MainBundle\Entity\CategoryRepository
factory_service: doctrine.orm.entity_manager
factory_method: getRepository
arguments: [ Allergo\MainBundle\Entity\Category ]
# .../Resourse/config/services.yml
imports:
- { resource: repositories.yml }
- { resource: controllers.yml }
services:
# allergo_main.example:
# class: Allergo\MainBundle\Example
# arguments: [@service_id, "plain_value", %parameter%]
/**
* @var CategoryRepository
*/
private $categoryRepository;
/**
* @param CategoryRepository $categoryRepository
*/
public function __construct
(
CategoryRepository $categoryRepository
)
{
$this->categoryRepository = $categoryRepository;
}
imports:
- { resource: "@AllergoMainBundle/Resources/config/services.yml" }
- { resource: parameters.yml }
- { resource: security.yml }
....
Answer the question
In order to leave comments, you need to log in
You have a controller as a service, you still need to look at the routing.
And it would be nice to look at the stack trace
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question