Zend Framework中的数据库驱动路由教程? [英] Tutorials For Database-Driven Routing in Zend Framework?

查看:72
本文介绍了Zend Framework中的数据库驱动路由教程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个需要使用数据库驱动的MVC方案的项目中,该方案中通过单个数据库表控制到控制器和视图的路由.但是,我没有找到任何使用该框架的当前版本进行演示的教程(它们似乎都是在多个版本之前编写的),并且我想知道是否有人使用最新版本进行了类似的操作框架,或者是否有人知道讨论如何以简单方式实现此目标的博客或教程.

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.

基本思想是将有一个sitePage表,其中包含pageName,controller,module和view字段.处理请求后,我需要在数据库中查询给定的pageName,并确定适当的控制器,模块和视图,然后将其传递给必要的Zend类,以继续进行正常的路由和请求处理.

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.

谢谢.

推荐答案

我意识到,使用路由器确实是一种更优雅的方法,但是为此,您需要通过扩展Zend_Controller_Router_Abstract类并实现该方法来创建自定义方法. 路线"方法.

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.

您将获得一个Zend_Controller_Request_Abstract对象作为"route"方法的参数.在那里您可以与数据库对话,然后可以使用:

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()

定义您的路线.

希望对您有帮助!

这篇关于Zend Framework中的数据库驱动路由教程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆