4

これまでのところ、beberlei DoctrineExtensions の実装に成功していません。MySQL Year() 関数が必要です。エラーは次のとおりです。

既知の関数が必要で、'Year' を取得しました

だから私は何かが欠けているに違いない。何?

これが私がこれまでに得たものです:

拡張機能は次の場所にインストールされます..\vendor\beberlei\lib\DoctrineExtensions

app/autoload.php の読み取り:

use Doctrine\Common\Annotations\AnnotationRegistry;

$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add('DoctrineExtensions', __DIR__.'/../vendor/beberlei/lib/DoctrineExtensions');

// intl
if (!function_exists('intl_get_error_code')) {
    require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';

    $loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

return $loader;

年関数の使用:

class ClientRepository extends EntityRepository {

    public function activeStatus($year, $status) {
        $em = $this->getEntityManager();
        $query = $em
                ->createQuery('select max(Year(ct.contact_date)) CY, 
                c.active
                from ManaClientBundle:Contacts ct
                join ManaClientBundle:Client c on ct.cid = c.id
                group by id')
            ->getResult();

        return $em->createQuery("select CY, count(CY) Status from
                $query where CY = $year and active = '$status'")
            ->getResult();
    }
}
4

1 に答える 1

5

YEAR 関数を Doctrine 設定に登録しましたか?

$this->getEntityManager()->getConfiguration()->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
于 2013-02-22T08:48:32.263 に答える