我不知道如何整合beberlei教义扩展: https://github.com/beberlei/DoctrineExtensions 在Zend Framework 2中使用Doctrine模块。 我用作曲家安装了它:
" beberlei / DoctrineExtensions":" dev-master"
我尝试使用我的module.config.php来自应用程序模块:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ .'_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/'.__NAMESPACE__.'/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__.'\Entity' => __NAMESPACE__. '_driver'
)
)
),
'configuration' => array(
'orm_default' => array(
'string_functions' => array(
'GroupConcat' => '/vendor/beberlei/DoctrineExtensions\Query\MsySql\GroupConcat'
)
)
)
),
但抛出了这个异常:
致命错误:类 ' /供应商/ beberlei / DoctrineExtensions \查询\ MsySql \ GroupConcat'不 结果
答案 0 :(得分:6)
配置不需要引用/vendor/beberlei
文件夹,因为这是由自动加载器处理的。
配置应该看起来像这样:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ .'_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/'.__NAMESPACE__.'/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__.'\Entity' => __NAMESPACE__. '_driver'
)
)
),
'configuration' => array(
'orm_default' => array(
'string_functions' => array(
'GroupConcat' => 'DoctrineExtensions\Query\Mysql\GroupConcat'
)
)
)
),
答案 1 :(得分:3)
使用Composer安装后
"beberlei/DoctrineExtensions": "dev-master"
在您的服务类中使用此代码:
$config = $this->getEntityManager()->getConfiguration();
$config->addCustomStringFunction('GROUP_CONCAT', 'DoctrineExtensions\Query\MySq\GroupConcat');
现在您可以使用' GROUP_CONCAT'你的DQL就像这样:
$dql = "SELECT GROUP_CONCAT(elem.name) FROM ..... GROUP BY ...";
$query = $this->getEntityManager()->createQuery($dql);
return $query->getArrayResult();
答案 2 :(得分:1)
对我有用
1-安装带有编辑器的DoctrineExtensions
composer require beberlei/DoctrineExtensions
2-将此行添加到autoload_classmapp.php
'DoctrineExtensions' => 'vendor/beberlei/DoctrineExtensions'
3-将此添加到module.config.php
'doctrine'=>array(
'configuration' => array(
'orm_default' => array(
'datetime_functions' => array(
'date' => 'DoctrineExtensions\Query\Mysql\Date',
'date_format' => 'DoctrineExtensions\Query\Mysql\DateFormat',
'dateadd' => 'DoctrineExtensions\Query\Mysql\DateAdd',
'datediff' => 'DoctrineExtensions\Query\Mysql\DateDiff',
'day' => 'DoctrineExtensions\Query\Mysql\Day',
'dayname' => 'DoctrineExtensions\Query\Mysql\DayName',
'last_day' => 'DoctrineExtensions\Query\Mysql\LastDay',
'minute' => 'DoctrineExtensions\Query\Mysql\Minute',
'second' => 'DoctrineExtensions\Query\Mysql\Second',
'strtodate' => 'DoctrineExtensions\Query\Mysql\StrToDate',
'time' => 'DoctrineExtensions\Query\Mysql\Time',
'timestampadd' => 'DoctrineExtensions\Query\Mysql\TimestampAdd',
'timestampdiff' => 'DoctrineExtensions\Query\Mysql\TimestampDiff',
'week' => 'DoctrineExtensions\Query\Mysql\Week',
'weekday' => 'DoctrineExtensions\Query\Mysql\WeekDay',
'year' => 'DoctrineExtensions\Query\Mysql\Year',
),
'numeric_functions' => array(
'acos' => 'DoctrineExtensions\Query\Mysql\Acos',
'asin' => 'DoctrineExtensions\Query\Mysql\Asin',
'atan2' => 'DoctrineExtensions\Query\Mysql\Atan2',
'atan' => 'DoctrineExtensions\Query\Mysql\Atan',
'cos' => 'DoctrineExtensions\Query\Mysql\Cos',
'cot' => 'DoctrineExtensions\Query\Mysql\Cot',
'hour' => 'DoctrineExtensions\Query\Mysql\Hour',
'pi' => 'DoctrineExtensions\Query\Mysql\Pi',
'power' => 'DoctrineExtensions\Query\Mysql\Power',
'quarter' => 'DoctrineExtensions\Query\Mysql\Quarter',
'rand' => 'DoctrineExtensions\Query\Mysql\Rand',
'round' => 'DoctrineExtensions\Query\Mysql\Round',
'sin' => 'DoctrineExtensions\Query\Mysql\Sin',
'std' => 'DoctrineExtensions\Query\Mysql\Std',
'tan' => 'DoctrineExtensions\Query\Mysql\Tan',
),
'string_functions' => array(
'binary' => 'DoctrineExtensions\Query\Mysql\Binary',
'char_length' => 'DoctrineExtensions\Query\Mysql\CharLength',
'concat_ws' => 'DoctrineExtensions\Query\Mysql\ConcatWs',
'countif' => 'DoctrineExtensions\Query\Mysql\CountIf',
'crc32' => ' DoctrineExtensions\Query\Mysql\Crc32',
'degrees' => 'DoctrineExtensions\Query\Mysql\Degrees',
'field' => 'DoctrineExtensions\Query\Mysql\Field',
'find_in_set' => 'DoctrineExtensions\Query\Mysql\FindInSet',
'group_concat' => 'DoctrineExtensions\Query\Mysql\GroupConcat',
'ifelse' => 'DoctrineExtensions\Query\Mysql\IfElse',
'ifnull' => 'DoctrineExtensions\Query\Mysql\IfNull',
'match_against' => 'DoctrineExtensions\Query\Mysql\MatchAgainst',
'md5' => 'DoctrineExtensions\Query\Mysql\Md5',
'month' => 'DoctrineExtensions\Query\Mysql\Month',
'monthname' => 'DoctrineExtensions\Query\Mysql\MonthName',
'nullif' => 'DoctrineExtensions\Query\Mysql\NullIf',
'radians' => 'DoctrineExtensions\Query\Mysql\Radians',
'regexp' => 'DoctrineExtensions\Query\Mysql\Regexp',
'replace' => 'DoctrineExtensions\Query\Mysql\Replace',
'sha1' => 'DoctrineExtensions\Query\Mysql\Sha1',
'sha2' => 'DoctrineExtensions\Query\Mysql\Sha2',
'soundex' => 'DoctrineExtensions\Query\Mysql\Soundex',
'uuid_short' => 'DoctrineExtensions\Query\Mysql\UuidShort',
),
)
)
)
答案 3 :(得分:1)
我的声誉太低而无法评论,但是:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ .'_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/'.__NAMESPACE__.'/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__.'\Entity' => __NAMESPACE__. '_driver'
)
)
),
'configuration' => array(
'orm_default' => array(
'string_functions' => array(
'GroupConcat' => 'DoctrineExtensions\Query\**MsySql**\GroupConcat'
)
)
)),
应该是:
'GroupConcat' => 'DoctrineExtensions\Query\**Mysql**\GroupConcat'
注意Mysql而不是MsySql