Zend 路由器逻辑
我正在努力解决如何处理我的 URL 映射。现在,我正在使用 Zend Framework 构建一个照片库系统。图库系统可以处理类别和图库。类别中可以包含子类别或画廊。显然,画廊有图像。这意味着我可以有以下 URL 可能性...
domain.com/gallery/ <== 主图库页面
domain.com/gallery/category1/gallery1/ <==显示图像库
domain.com/gallery/category1 /category2/ <== 显示画廊图库
domain.com/gallery/category1/category2/gallery1 <== 显示图像画廊
domain.com/gallery/category3/gallery2/image1 <== 显示单个图像页面
domain .com/gallery/gallery3/ <== 禁用类别,因此它显示图像库
如何处理多个选项?如果有一个简单的任务,它总是 /{category}/{gallery}/{image}/ 那么我可以把它放在一起。但我正在努力解决如何在变量数量发生变化的情况下管理它。
如果我假设每个图库/类别/图像都有一个唯一的名称,这意味着图库和类别不共享相同的名称,那么我可以简单地忽略除最后一个变量之外的所有变量。我可以设置一个脚本,该脚本采用最后一个变量,将其与图像表、图库表和类别表进行比较,然后在第一个变量命中时将其转发到正确的视图。虽然这听起来相当资源密集,每次调用图库系统可能需要 3 个模型查询,但我无法理解任何其他方法来实现它。
有人有什么想法或建议可以最有效地做到这一点吗?
I am struggling with how to handle my URL mapping. Right now, I am working on putting together a photo gallery system using the Zend Framework. The gallery system can handle categories and galleries. A category can have child categories or galleries in it. Obviously, a gallery has an image. This means I could have the following URL possibilities...
domain.com/gallery/ <== main gallery page
domain.com/gallery/category1/gallery1/ <==displays gallery of images
domain.com/gallery/category1/category2/ <== displays gallery of galleries
domain.com/gallery/category1/category2/gallery1 <== displays gallery of images
domain.com/gallery/category3/gallery2/image1 <== displays single image page
domain.com/gallery/gallery3/ <== disabled categories therefore it displays a gallery of images
How can I handle multiple options? If there was a simple task where it was always going to be /{category}/{gallery}/{image}/ then I could put it together. But I am struggling with how to manage it where the number of variables change.
If I run with the assumption that the each Gallery/Category/Image has a unique name meaning a gallery and category don't share the same name, then I can simply ignore all of the variables except the last one. I could set up a script that takes the last variable, compares it to the image table, the gallery table, and then the category table, and then forwards it to the correct view when the first variable gets a hit. While this sounds fairly resource intensive with possibly 3 model queries for each call to the gallery system, I can't fathom any other way to go about it.
Anyone have any ideas or suggestions to do this most efficiently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IMO,URL 不需要知道类别的层次结构。如果您同意并考虑到该画廊是一个控制器,您可以像这样解决它:
这意味着您只有一个显示操作,其余的作为参数传递。如果您传递参数画廊,您将显示具有相应 ID 的画廊,如果您传递参数类别,您将检查该类别是否有子类别并显示它们或相应的画廊。
您还可以考虑一个解决方案,其中有一个图库模块、一个显示控制器和图库、类别、图像操作。在这种情况下,您需要在 url 中添加 /id/ 部分:
让您的模型找出层次结构并用面包屑或类似的方式反映它。
The url doesn't need to know the hierarchy of categories, IMO. If you agree and given that gallery is a controller you could solve it like this:
Which would mean you just have a display action and you pass the rest as params. In case you pass the param gallery, you show the gallery with the respective ID, in case you pass the param category, you check, if this category has subcategories and show them or the respective galleries.
You could also think of a solution where you have a gallery module, a display controller and gallery, category, image actions. In that case you would need to add an /id/ part in the url:
Let your model figure out the hierarchy and reflect it with breadcrumbs or similar.