Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tutorials For Database-Driven Routing in Zend Framework?

I am working on a project that needs to use a database driven MVC scheme where the route to the controllers and views are controlled through a single database table. However, I haven't been able to find any tutorials that demonstrate this with a current version of the framework (they all appear to have been written several versions ago) and I was wondering if anyone has done something like this with a more recent version of the framework or if anyone knows of blogs or tutorials that discuss how to accomplish this in a simple manner.

The basic idea is that there will be a sitePage table that will contain pageName, controller, module and view fields. When the request is processed I need to query the database for the given pageName and determine the appropriate controller, module and view and then pass this into the necessary Zend class to continue with the normal routing and processing of the request.

Thanks in advance.

like image 599
Noah Goodrich Avatar asked Jan 23 '23 22:01

Noah Goodrich


1 Answers

You can also use the routeStartup() method in your plugin. eg:

 class My_Plugin_PageRoute extends Zend_Controller_Plugin_Abstract {

     public function routeStartup ()  {
         $front = Zend_Controller_Front::getInstance();
                    $pages = new Model_Pages();
                    $page_data = $pages ->getPageInfo();

        $router = $front->getRouter();

        foreach($page_data as $page) {
            $r = new Zend_Controller_Router_Route(
                '' . $page -> page_name,
                array('controller' => 'pages',
                      'action' => 'index',
                      'page_id' => $page -> page_id)
            );
            $router->addRoute('pages_' . $page -> page_id, $r);
        }

     }

 }
like image 175
Anders Avatar answered Feb 02 '23 08:02

Anders