Year() and Beberlei/Doctrineextensions
I Have to Make Requests with Year and I Installed Beberlei/Doctrineextensions with Doctrine Command. I Added the Requested Annotations Doctrine: Orm...
I have to make requests with YEAR and I installed beberlei/DoctrineExtensions with doctrine command. I added the requested annotations
doctrine:
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
datetime_functions:
year: DoctrineExtensions\Query\Mysql\Year
, but it does not work, I have this error:
Attempted to load class "Year" from namespace "DoctrineExtensions\Query\Mysql". Did you forget a "use" statement for another namespace?
The request:
public function groupTypeInterArray(){
$qb = $this->createQueryBuilder('i')
->select('YEAR(i.interventionDate)');
return $qb->getQuery()->execute();
}
Config Doctrine
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
datetime_functions:
Year: DoctrineExtensions\Query\Mysql\Year
I searched all the afternoon, but I didn't find the solution.
Thank you in advance.
3 Answers
1.dql:
datetime_functions:
year: DoctrineExtensions\Query\Mysql\Year ???
2.dql:
datetime_functions:
Year: DoctrineExtensions\Query\Mysql\Year ???
Maybe
dql:
datetime_functions:
YEAR: DoctrineExtensions\Query\Mysql\Year
MONTH: DoctrineExtensions\Query\Mysql\Month
DAY: DoctrineExtensions\Query\Mysql\Day
For me removing the vendor dir and do a fresh composer install solved the problem.
in the query replace "Year" with "year"
so use the following code instead:
public function groupTypeInterArray(){
$qb = $this->createQueryBuilder('i')
->select('year(i.interventionDate)');
return $qb->getQuery()->execute();
}
and you also need to change the corresponding line in the doctrine config :
replaces this code
Year: DoctrineExtensions\Query\Mysql\Year
By this code
year: DoctrineExtensions\Query\Mysql\Year
PS : to know which link you have to use to add a function correctly in doctrine config you have to go on this link