0

I have 3 records of datatype in database and two of them have different year. My sql query is: 'SELECT DISTINCT YEAR(postdate) from post'.

in PostRepository.php I have such function:

<?php namespace Dev\TaskBundle\Entity; use Doctrine\ORM\EntityRepository; use Doctrine\DoctrineExtensions\Query\Mysql; class PostRepository extends EntityRepository{ public function getYears(){ return $this->createQueryBuilder('p') ->select('YEAR(p.postdate')->distinct() ->getQuery() ->getResult(); } } 

I had configured config.yml before and the error I receive is:

Attempted to load class "Year" from namespace "DoctrineExtensions\Query\Mysql". Did you forget a "use" statement for another namespace?

Could someone explain what's wrong?

1
  • can you show your config.yml - your YEAR extension is not used Commented Sep 9, 2015 at 13:07

1 Answer 1

0

You forgot to configure extension for YEAR function. You can do it via config.yml:

doctrine: orm: dql: string_functions: YEAR: DoctrineExtensions\Query\Mysql\Year 
Sign up to request clarification or add additional context in comments.

3 Comments

Hello. Thanks for your answer. My URL in project is 'localhost:8000/web/app_dev.php/' Am i in development environment then? Should I put that in config_dev.yml ? I posted my config.yml below and error keeps poping
in a standard setup config.yml is used by any stage and e.g. config_dev is then adding/replacing special requirements to the config.yml - if that's ok then you shouldn't have an issue with that point.
If this attempt didn't solve your problem can you say what error do you have now?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.