現在の(2.1)ZF2ユーザーガイドの「データベースとモデル」の章にコードスニペットがありますが、わかりません:
(ブロック "ServiceManager を使用してテーブル ゲートウェイを構成し、AlbumTable に挿入する")
...
class Module
{
// getAutoloaderConfig() and getConfig() methods here
// Add this method:
public function getServiceConfig()
{
return array(
'factories' => array(
'Album\Model\AlbumTable' => function($sm) {
$tableGateway = $sm->get('AlbumTableGateway');
$table = new AlbumTable($tableGateway);
return $table;
},
'AlbumTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Album());
return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
},
),
);
}
}
変数$sm
は後で のインスタンスになりますZend\ServiceManager\ServiceManager
よね?メソッド Zend\ServiceManager\ServiceManager#get(...) は、最初の引数としてクラス名を想定しています。ただし、クラス AlbumTableGateway はありません。モデル クラスは、Album\Model\Album と Album\Model\AlbumTable の 2 つだけです。
ガイドの間違いですか、それともコードの理解が間違っていますか?
ありがとう