Zend Framework 的不同 url 方案

发布于 2024-08-26 11:24:31 字数 527 浏览 3 评论 0原文

对于我们的 CMS,我们有一个站点管理器,用于定义站点的树结构(如果您想这样称呼它,则称为站点地图)。

可能的 URL 是 www.example.com/our-team/developers/chris/,它将在树结构中映射到节点 chris,它是开发人员的子节点,而开发人员又是外团队的子节点。

所有这一切都已就位并有效,这要归功于学说中嵌套集行为的完美实现。唯一的问题是我正在努力让它在我们网站的前端运行。默认情况下,Zend 框架的请求对象需要控制器/操作/键/值/键/值/... URI 方案,但这不太符合我的需求,我想跳过整个控制器、操作和关键部分并限制为价值观。像 value1/value2/value3/value4/...

任何人都知道如何实现这一点?

编辑:更多背景: 您可能想知道我如何将请求映射到控制器/操作?好吧,每个不可分派的请求(因此不是现有的控制器/操作)都由错误控制器处理,我在那里将请求 URI 与树结构中的路径进行匹配,从而能够显示页面(如果路径匹配),如果不匹配,错误控制器将继续并响应 404。

For our CMS we have a site manager that defines the site's tree structure (sitemap if you want to call it that).

A possible url is www.example.com/our-team/developers/chris/ which would map in the tree structure to the node chris, child of developers which is in turn a child of out-team.

All this is in place and working thanks to the wonderfully implemented Nested Set behavior in doctrine. The only thing is that i'm struggling to get it working in the front end of our website. By default Zend framework's request object expects controller/action/key/value/key/value/... URI scheme but that isn't quite fitting my needs, i would like to skip the whole controller, action and key part and restrict to values. Something like value1/value2/value3/value4/...

Anyone has an idea how to accomplish this?

Edit: Some more background:
You probably wonder how i'm mapping the request to a controller/action? Well every request that isn't dispatchable (thus isn't an existing controller/action) is handled by the error controller, it is there where i match the request URI against a path in the tree structure and thus am able to display the page (if the path matches), if it doesn't match the error controller just continues and a 404 is responded.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

美人迟暮 2024-09-02 11:24:31

我通过扩展 Zend_Controller_Router_Route_Abstract 类来完成路由。

通过将其添加到路由器堆栈中,可以使用使用许多路由的“瀑布”系统。

在我的博客上发布了代码按照Bittarman的建议工作。

I accomplished the routing by extending the Zend_Controller_Router_Route_Abstract class.

By adding it to the router stack, it is possible to use a 'waterfall' system using many routes.

I published the code on my blog and it works as Bittarman suggested.

横笛休吹塞上声 2024-09-02 11:24:31

该用例映射到与标准模式类似的控制器/操作/值。定义自定义路由时,请使用类似 :controller/:action/:username 的内容。

请参阅使用路由器在 ZF 的手册中。

That use case maps up to controller/action/value which is similiar to the standard pattern. Use something like :controller/:action/:username when defining your custom route.

See Using a Router in the manual for ZF.

巨坚强 2024-09-02 11:24:31

首先,我将停止使用错误控制器来提供路由。那简直就是糟糕的juju。

现在,在处理这样的路由结构时需要考虑一些事情,其中​​之一是这与默认路由冲突,因此如果您依赖它,则需要严格执行此操作。

鉴于您在此处提供的信息,我建议您对路由类进行子类化,并对数据库执行(缓存)查找,然后从那里返回正确的模块/控制器/操作,然后直接转到正确的操作首位。

然后,您还可以在请求参数(页面内容、团队成员详细信息等)中传递相关数据,以便您的操作中不需要进一步的数据库查找,并且如果没有查找麻烦,您的操作代码也不需要。

Firstly, I'd stop using the error controller to provide routing. Thats just plain bad juju.

Now there are a few things to consider when dealing with a routeing structure like this, one is that this conflicts with the default route, so if your relying on it, your going to need to be strict about how you do so.

given the information you have made available here, I would suggest you subclass the route class, and perform a (cached) lookup against your database, and return the correct module/controller/action from there, and go straight to the correct action in the first place.

You can also then pass the relevant data along in the request params (page content, team member details etc) so that a further db lookup is not required in your action, and your action code if free of lookup cruft.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文