如何在Zend Framework 2中配置(和使用)多个数据库?目前我在global.php中有这个:
return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=my_db;host=localhost',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
'username' => 'user',
'password' => '******',
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
);
Run Code Online (Sandbox Code Playgroud)
但我没有看到添加第二个的方法.
在Zend Framework 1中,我有几个映射器从父Mapper类继承了setDbTable和getDbTable.
现在在ZF2中面对我需要模型中的服务管理器的问题,我不知道如何获取它:
class Mapper
{
protected $tableGateway;
protected $module = 'application';
public function setTableGateway($table)
{
if (is_string($table)) {
$class = $this->module . '\Model\DbTable\\' . ucfirst($table);
$sm = $this->getServiceLocator(); <= Fatal error: Call to undefined method Mapper::getServiceLocator()
$tableGateway = (class_exists($class)) ? $sm->get($class) : $sm->get(new TableGateway($table));
} else {
$tableGateway = $table;
}
if (!$tableGateway instanceof Zend\Db\TableGateway\AbstractTableGateway) {
throw new \Exception('Invalid table data gateway provided');
}
$this->tableGateway = $tableGateway;
return $this;
}
// more code
Run Code Online (Sandbox Code Playgroud)
这条线:
$sm = $this->getServiceLocator();
Run Code Online (Sandbox Code Playgroud)
给出致命错误: …
在提交表单时,我希望将访问者发送到外部网址以执行某些操作,但希望他之后继续浏览我的网站.在html中,我会用href ="http://www.example.com"target ="_ blank"给他机会.
但是当我这样做时,我找不到怎么做:
$this->_helper->redirector->gotoUrl('http://www.example.com');
Run Code Online (Sandbox Code Playgroud)
在我的控制器动作中.在Google,文档和SO中都找不到任何内容.这是不可能的吗?