如何在我的表模型中获得默认的数据库适配器?我想用它来创建交易。
在 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 个抽象方法,因此必须声明为抽象方法或在