テーブルモデルでデフォルトのdbadabterを取得するにはどうすればよいですか?トランザクションの作成に使用したいと思います。
database.global.php内:
return array(
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
'aliases' => array(
'db' => 'Zend\Db\Adapter\Adapter',
),
),
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=cww;host=localhost',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
);
今
$this->adapter
、私は私のalbumTable.phpに入れたいです
私はそれを次のように受け取ろうとしました:
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql\Expression;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Update;
use Zend\Db\Sql\Sql;
use Zend\Db\Sql\Where;
use Ajax\Model\Album;
class AlbumTable implements ServiceLocatorAwareInterface
{
protected $tableGateway;
protected $adapter;
public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
$this->adapter = $this->getServiceLocator()->get('db');
}
しかし、エラーが発生します:
致命的なエラー:クラスAjax \ Model \ AlbumTableには2つの抽象メソッドが含まれているため、抽象として宣言するか、残りのメソッド(Zend \ ServiceManager \ ServiceLocatorAwareInterface :: setServiceLocator、Zend \ ServiceManager \ ServiceLocatorAwareInterface :: getServiceLocator)を実装する必要があります。