phpzend-frameworkurl-routingmodel-view-controllerdatabase-driven

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.


Solution

  • I realized that a more elegant approach is indeed to use a router, but for that you would need to create a custom one by extending the Zend_Controller_Router_Abstract class and implementing the "route" method.

    You get a Zend_Controller_Request_Abstract object as the parameter of the "route" method. There you can talk to the database and then you can use:

    Zend_Controller_Request_Abstract::setModuleName(),
    Zend_Controller_Request_Abstract::setControllerName(),
    Zend_Controller_Request_Abstract::setActionName()
    

    to define your route.

    I hope it helps!