编写控制器/动作时 Zend_Navigation 与 Zend_Router 不兼容?
Zend 框架开发新手尝试找出 Zend 路由问题的简单解决方案。我确信你们中的一位专业人士可以伸出援手。
我有一个网站(使用 Zend_Navigation 在 Zend Framework 中构建),其中包含 75% 的静态 HTML 页面内容和一些控制器。顶级导航是在 Zend_Navigation 中构建的,循环遍历局部。
由于我的工作,我沿着这些思路构建了很多网站(包含大量静态页面),所以我想把它做好。我不想为每个静态页面(有很多)设置控制器和操作,我想创建一个解决方案,使用 Zend_Controller_Router_Route
自动路由所有静态内容到一个 StaticController
,其工作是根据 URL 中的控制器/动作配对包含或渲染 .phtml 页面,这些目录来自某种目录,例如 /layouts/staticpages
因为SEO 和各种原因我不想让这些静态页面的 URL 中的控制器配对显示为 /static/page/page1
...它必须是“真实世界的描述” /section/page
的(例如 advantages/someadvantage
)
这是问题:当我设置正确的路线,但它把 Zend Navigation 弄乱了……我想是因为 Zend_Navigaion 不能很好地处理动态控制器/动作切换。
代码示例:
$router = Zend_Controller_Front::getInstance()->getRouter();
$route = new Zend_Controller_Router_Route('advantages/:page/*',
array('controller' => 'static', 'action' => 'display', 'mode' => 'advantages',
'page' => 'index'));
$router->addRoute('advantages', $route);
这很好地处理了“优点”部分中切换页面的工作,但是 Zend_Navigation 的自动控制器/动作编写以及“活动”节点的突出显示最终都搞砸了,因为它现在认为其控制器是“静态的” ”,动作是“显示”。
Zend_Navigation 与 Zend_Controller_Router_Route
根本不兼容吗?有没有更好的方法来执行这个单一静态页面控制器或全面处理静态内容?
Novice Zend Framework developer here trying to figure out a simple solution to a Zend Routing problem. I'm sure one of you pros can lend a hand.
I have a website (built in Zend Framework using Zend_Navigation) that contains 75% static HTML page content and a few controllers. Top level navigation is built in Zend_Navigation, looping through partials.
Because of my work I build a lot of sites along these lines (containing lots of static pages) so I want to get this right. I don't want to set up controllers and actions for each and every one of these static pages (there are many) and I wanted to create a solution where I used Zend_Controller_Router_Route
to route all static content automatically through to a StaticController
whose job it would be to include or render .phtml pages based on a controller/action pairing in the URL from some sort of directory like /layouts/staticpages
Because of SEO and various reasons I don't want to have the controller pairing in the URL for these static pages be visible as /static/page/page1
... It has to be "real world descriptions" of the /section/page
(eg. advantages/someadvantage
)
Here is the problem: Using Zend_Controller_Router_Route
can do the job when I set up the correct routes BUT it messes something awful with Zend Navigation... I assume because Zend_Navigaion doesn't play nice with on-the-fly controller/action switching.
Code example:
$router = Zend_Controller_Front::getInstance()->getRouter();
$route = new Zend_Controller_Router_Route('advantages/:page/*',
array('controller' => 'static', 'action' => 'display', 'mode' => 'advantages',
'page' => 'index'));
$router->addRoute('advantages', $route);
This handles the job of switching pages in the "advantages" section well enough, but Zend_Navigation's automatic controller/action writing AND the highlighting of "active" nodes ends up being all screwed up because it now thinks that its controller is "static" and action is "display".
Is Zend_Navigation fundamentally incompatible with Zend_Controller_Router_Route
? Is there a better way of doing this single static page controller or handling static content across the board?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您对所有静态页面使用一个控制器/操作,因此您必须在显示 Zend Navigation 之前对其进行自定义。
查看Zend 文档中的示例 4。
Since you are using one controller/action for all static pages, you must customize your Zend Navigation before displaying it.
Check Example 4 in the Zend Documentation.