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?

tftd
  • 16,203
  • 11
  • 62
  • 106

1 Answers1

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
Michael Sivolobov
  • 12,388
  • 3
  • 43
  • 64
  • 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 – Hans Schwimmer Sep 09 '15 at 16:08
  • 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. – LBA Sep 09 '15 at 16:42
  • If this attempt didn't solve your problem can you say what error do you have now? – Michael Sivolobov Sep 09 '15 at 19:20