ZF2 での Doctrine の実装に関するこの便利なチュートリアルを読んでください。Module.php と config/local.php にグローバル設定オプションを配置する必要があります。Module.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'
)
)
)
)
そして、local.php のこれらの DB 接続パラメーター:
return array(
// ...
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'user' => '',
'password' => '',
'dbname' => 'zf2tutorial',
)
)
)
),
);
これにより、DB エンティティでの繰り返しを避けることができ、クラスごとに次の Doctrine 宣言のみを使用できるようになります。
/**
* A music album.
*
* @ORM\Entity
* @ORM\Table(name="album")
* @property string $artist
* @property string $title
* @property int $id
*/
class Album implements InputFilterAwareInterface {