通过PageController路由除现有控制器以外的所有请求(Zend Framework) [英] Route all requests through PageController except existing controllers (Zend Framework)

查看:60
本文介绍了通过PageController路由除现有控制器以外的所有请求(Zend Framework)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于新的CMS,我开发了一个Pages模块,该模块使我可以管理网站的树形结构。每个页面都可以通过网址 http://www.example.com/pageslug/ 访问,其中pageslug

For a new CMS i've developed a Pages module that allows me to manage the site's tree structure. Each page is reachable from the url http://www.example.com/pageslug/ where pageslug identifies the page being called.

我现在想要实现的是一条路由,该路由允许我将所有传入请求路由到单个PagesController,除非它是对现有控制器的请求(例如图像)。

What I want to achieve now is a route that allows me to route all incoming requests to a single PagesController unless it's a request to an existing controller (like images for example).

捕获所有对Pages Controller的请求很容易,但是如何排除现有的控制器呢?
这是我的模块引导程序。我如何以最可取的方式实现这一目标

It's easy enough to catch all requests to the Pages Controller but how to exclude existing controllers? This is my module bootstrap. How can i achieve this in the most preferrable way

<?php

class Default_Bootstrap extends Zend_Application_Module_Bootstrap
{

    protected function _initRoute()
    {
        $this->bootstrap('frontController');

        /* @var $frontcontroller Zend_Controller_Front */
        $frontcontroller = $this->getResource('frontController');

        $router = $frontcontroller->getRouter();
        $router->addRoute(
            'all',
            new Zend_Controller_Router_Route('*',
                array('controller' => 'pages',
                      'action'     => 'view')
            )
        );

    }

}


推荐答案

Zend路由按顺序工作-如果在第一条路由之后添加第二条路由,则如果匹配则将优先 。在我自己的Zend项目中,我有一堆路线,第一个路线很像您的路线,可以一路走走。但是,它下面任何与url匹配的内容都会覆盖它-因此,只需尝试添加稍微更具体的路由(如果所有/ user /请求都发送到user_controller,则添加/ user / *路由)

Zend routes work in order - if you add a second route after your first, it will take precedence if it matches. In my own Zend project I've got a bunch of routes, the first of which is much like yours, a catch all route. However, anything below it that matches the url overrides it - so just try adding slightly more specific routes (if all your /user/ requests go to your user_controller, add a /user/* route)

这篇关于通过PageController路由除现有控制器以外的所有请求(Zend Framework)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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