I'll try to by as clear as possible : I have the need to use SQL in one of my repository. I've read on the internet that I have to use Doctrine's DBAL to make it work. I took one of the exemple of it here : How do you access Doctrine DBAL in a Symfony2 service class? or there http://inchoo.net/dev-talk/doctrine-dbal-with-symfony2/
Here's my repo :
class myRepository
{
private $conn;
public function __construct(Connection $conn){
$this->conn = $conn;
}
public function getStuff(){
$sql = "SELECT * FROM stuff";
return $this->conn->fetchAll($sql);
}
}
The problem is on the $conn parameter in the constructor. I'm trying to get a DBAL\connection object and get an EntityManager instead.
Here's my Bundle/Resources/config/services.yml
services:
my_repo:
class: MyBundle\Repository\MyRepository
arguments: ["@doctrine.dbal.default_connection"]
and the app/config.yml doctrine part :
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
Finally, here's the error :
Catchable Fatal Error: Argument 1 passed to MyBundle\Repository\MyRepository::__construct() must be an instance of Doctrine\DBAL\Connection, instance of Doctrine\ORM\EntityManager given, called in D:\dev\php\MyProject\vendor\doctrine\orm\lib\Doctrine\ORM\Repository\DefaultRepositoryFactory.php on line 68 and defined 500 Internal Server Error - ContextErrorException
Does anybody have any idea about this error, and how to fix it ?
Nb: I already tried not naming my connection in app/config.yml, because i guess it should be reserved for multiple connections. I also tried to use "@database_connection" as an argument of my repo's constructor, also tried "@doctrine.dbal" while my connection's not named.
Nb2: if needed, here's a part of my composer.json
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",