I am trying to store custom routes for the Zend Framework inside the database. I have the process down that will create the route, but the problem I am running into is that when I am adding the routes it looks like Zend has not yet created its connection to the database.
Does anyone know where this processes initially happens or how I can force the database to connect from the init_routes function inside Bootstrap.php?
UPDATE:
What I am doing from Bootstrap.php is calling a model that will return all the Zend_Controller_Router_Route_Static objects for the vendors. Here is the code I am using inside Bootstrap.php
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$vendor_routes = new Application_Model_Vendor();
$vendor_routes = $vendor_routes->getStaticRoutes();
The code inside the getStaticRoutes() function is as follows:
public function getStaticRoutes() {
$select = $this->select();
$select->from($this)
->where("featured = 1");
$rows = $this->fetchAll($select);
foreach($rows as $row) {
print_r($row);
}
}
This function is contained in a model that extends Zend_Db_Table_Abstract
The error that I am getting is as follows:
<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 />
Thanks again!
It should connect on demand. If you have an equivalent init method for initialising your database connection, you just need to ensure that this is bootstrapped before your routes, like this:
Edit: okay, looks like you just need to tell Zend_Db_Table to use your DB connection. In code you’d do:
in application.ini I think you can do:
which I’m guessing you don’t currently have. See if that fixes your issue. See the DB section on http://framework.zend.com/manual/en/zend.application.available-resources.html for a fuller example.