A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearTutorials For Database-Driven Routing in Zend Framework? - page 1
User InfoPosts
Tutorials For Database-Driven Routing in Zend Framework?#1
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.

posted date: 2008-12-19 12:55:00


Re: Tutorials For Database-Driven Routing in Zend Framework?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-19 12:55:01


Re: Tutorials For Database-Driven Routing in Zend Framework?#3
Maybe the best aproach is not by using routers but by using plugins or a common controller. Without a deeper analysis I would suggest you to create a Front Controller Plugin, and then inside the preDispatch() method you can talk to the database and reset the request so it is dispatched to the right controller.You can also get the same effect by using a common controller, all requests are routed to it then it can forwards to the right controller after talking to the database, although I prefer to use a plugin.From the Manual:preDispatch() is called before an action is dispatched by the dispatcher. This callback allows for proxy or filter behavior. By altering the request and resetting its dispatched flag (via Zend_Controller_Request_Abstract::setDispatched(false)), the current action may be skipped and/or replaced. http://framework.zend.com/manual/en/zend.controller.plugins.html

posted date: 2008-12-19 13:43:00


Re: Tutorials For Database-Driven Routing in Zend Framework?#4
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!

posted date: 2008-12-19 13:53:00


Re: Tutorials For Database-Driven Routing in Zend Framework?#5
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); } } }

posted date: 2011-04-04 23:52:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.