我是Zend Framework的新手,我正在努力与Zend_Queue
合作。我把这段代码放在bootstrap中,但它抛出异常。 Bootstrap.php中的代码:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
protected function _initDatabase() {
$options = array(
'name' => 'queue',
'driverOptions' => array (
'host' => '127.0.0.1',
'port' => '3306',
'username' => 'root',
'password' => '',
'dbname' => 'queue',
'type' => 'pdo_mysql'
)
);
}
protected function _initQueue() {
$options = $this->getOptions();
$queueAdapter = new Zend_Queue_Adapter_Db($options['queue']);
Zend_Registry::getInstance()->queueAdapter = $queueAdapter;
}
}
这是我得到的错误:
Fatal error:
Uncaught exception 'Zend_Queue_Exception' with message 'Adapter options must be an array or Zend_Config object' in
C:\wamp\library\ZendFramework\library\Zend\Queue\Adapter\AdapterAbstract.php:110 Stack trace: #0
C:\wamp\library\ZendFramework\library\Zend\Queue\Adapter\Db.php(83): Zend_Queue_Adapter_AdapterAbstract->__construct(NULL, NULL) #1
C:\wamp\www\queue2\application\Bootstrap.php(28): Zend_Queue_Adapter_Db->__construct(NULL) #2 C:\wamp\library\ZendFramework\library\Zend\Application\Bootstrap\BootstrapAbstract.php(667): Bootstrap->_initQueue() #3
C:\wamp\library\ZendFramework\library\Zend\Application\Bootstrap\BootstrapAbstract.php(620): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('queue') #4
C:\wamp\library\ZendFramework\library\Zend\Application\Bootstrap\BootstrapAbstract.php(584): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL) #5
C:\wamp\library\ZendFramework\library\Zend\Application.php(355): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap(NULL) #6
C:\wamp\w in C:\wamp\library\ZendFramework\library\Zend\Queue\Adapter\AdapterAbstract.php on line 110
答案 0 :(得分:1)
尝试将您设置的$options
移动到与_initQueue()
相同的方法,并传递整个$options
数组而不是$options['queue']
。除非$options['queue']
中包含某些内容,否则application.ini
似乎不会定义。
尝试:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
protected function _initQueue() {
$options = array(
'name' => 'queue',
'driverOptions' => array (
'host' => '127.0.0.1',
'port' => '3306',
'username' => 'root',
'password' => '',
'dbname' => 'queue',
'type' => 'pdo_mysql'
)
);
$queueAdapter = new Zend_Queue('Db', $options);
Zend_Registry::getInstance()->queueAdapter = $queueAdapter;
}
}