Hi,

I need to create some routes based on the database so based on what I've
read/suggestions I'll have to change the way  I am doing it today.

Since I'll have to pull from the database the correct way should be to
write a plugin (
http://framework.zend.com/manual/en/zend.controller.plugins.html) and
create a routeStartup where I should access the database, create my routes
and do something like this

$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory('/path/to/controllers')
      ->setRouter(new Zend_Controller_Router_Rewrite())
      ->registerPlugin(new MyPlugin());
$front->dispatch();

So my questions are:
a) Where should I add this registerPlugin since in my index.php I am not
actually calling the dispatch?

b) My plugin could be like this?

class MyPlugin extends Zend_Controller_Plugin_Abstract {
public function routeStartup(Zend_Controller_Request_Abstract $request) {

   $frontController = Zend_Controller_Front::getInstance();
   $router = $frontController->getRouter();
   // Get the info from the db
  foreach ($dbInfo as $info) {
      $route = new Zend_Controller_Router_Route (
                    'something/',
                    array('controller' => 'real-controller',
                          'action'     => 'index',
                          'id'         => X));

        $router->addRoute('something', $route);
  }

Right now I have my zf.sh-generated index.php and Bootstrap.php.

In my index.php

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();

And in my Bootstrap.php

protected function _initRoutes()
    {
        $frontController = Zend_Controller_Front::getInstance();
        $router = $frontController->getRouter();

        $route = new Zend_Controller_Router_Route (
                    'something/',
                    array('controller' => 'real-controller',
                          'action'     => 'index',
                          'id'         => X));

        $router->addRoute('something', $route);
}

protected function _initDatabase()
{
....
}

Reply via email to