我怎样才能在我的表模型的默认数据库adabter? 我想用它来创建一个事务。
在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 \模型\ AlbumTable包含2种抽象方法,因此必须声明为抽象或实现其余的方法(Zend的\的ServiceManager \ ServiceLocatorAwareInterface :: setServiceLocator,Zend的\的ServiceManager \ ServiceLocatorAwareInterface :: getServiceLocator)在