我想存储数据库中的Zend框架的自定义路由。我已经创建了路线,但我遇到的问题是,当我添加路线时,它看起来像Zend尚未创建与数据库的连接。强制Zend框架连接到数据库比平常早
有谁知道这个过程最初发生在哪里,或者我可以如何强制数据库从Bootstrap.php中的init_routes函数进行连接?
UPDATE:
什么我从bootstrap.php中做的是调用了一个模型,将返回所有的厂商Zend_Controller_Router_Route_Static对象。这里是我使用内部bootstrap.php中
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$vendor_routes = new Application_Model_Vendor();
$vendor_routes = $vendor_routes->getStaticRoutes();
的getStaticRoutes中的代码()函数是如下的代码:
public function getStaticRoutes() {
$select = $this->select();
$select->from($this)
->where("featured = 1");
$rows = $this->fetchAll($select);
foreach($rows as $row) {
print_r($row);
}
}
该功能被包含在延伸Zend_Db_Table_Abstract
一个模型我得到的错误如下:
<b>Fatal error</b>: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for Application_Model_Vendor' in /var/www/vhosts/weddingdir/weddingdir/library/Zend/Db/Table/Abstract.php:754
Stack trace:
#0 /var/www/vhosts/weddingdir/weddingdir/library/Zend/Db/Table/Abstract.php(739): Zend_Db_Table_Abstract->_setupDatabaseAdapter()
#1 /var/www/vhosts/weddingdir/weddingdir/library/Zend/Db/Table/Abstract.php(268): Zend_Db_Table_Abstract->_setup()
#2 /var/www/vhosts/weddingdir/weddingdir/application/Bootstrap.php(17): Zend_Db_Table_Abstract->__construct()
#3 /var/www/vhosts/weddingdir/weddingdir/library/Zend/Application/Bootstrap/BootstrapAbstract.php(666): Bootstrap->_initRoutes()
#4 /var/www/vhosts/weddingdir/weddingdir/library/Zend/Application/Bootstrap/BootstrapAbstract.php(619): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('routes')
#5 /var/www/vhosts/weddingdir/weddingdir/library/Zend/Application/Bootstrap/BootstrapAbstract.php(583): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NUL in <b>/var/www/vhosts/weddingdir/weddingdir/library/Zend/Db/Table/Abstract.php</b> on line <b>754</b><br />
ks再次!
My Bootstrap.php里面没有_initDb()。我会假设它在需要时连接到数据库(它在应用程序中的其他任何地方),但是在Bootstrap内部没有。我在想这是因为数据库连接信息存储在application.ini文件中,并且它可能还没有解析该文件或其他东西。 – 2010-10-11 20:07:29
application.ini的东西在所有的_init方法之前运行,所以你应该没问题。你可以发表你如何访问/使用路径方法中的db类的例子吗? $这 - >的getResource( 'DB');应该根据application.ini数据设置DB类,以便您可以尝试使用var_dump()来查看所获得的结果。 – 2010-10-11 20:09:50
我在第一篇文章中添加了更多信息。 – 2010-10-11 20:28:27