代码之家  ›  专栏  ›  技术社区  ›  meder omuraliev

Zend:依赖通用页面控制器时清除URL?

  •  1
  • meder omuraliev  · 技术社区  · 15 年前

    我正在使用的应用程序具有页面结构设置,因此当您创建一个新页面并查看它时,URI是:

    http://site.com/page/open/title/Contact Us
    

    一个客户机请求我们需要缩短的URL,例如,前面的URI应该类似于 http://site.com/contact-us/

    之所以有一个通用的页面控制器,是因为这些页面在管理区域中具有可编辑的内容区域,并且使用这种结构更容易控制它们。

    关于缩短它们的要求,我该怎么做呢?例如,我应该为20页中的每一页创建控制器并以某种方式重新路由它们,还是在初始页控制器中设置某种方法作为 open/title/ page/name/Contact Us ?我会认为依赖自定义重写规则是一个肮脏的解决方案,我不需要使用任何规则,也许我错了?

    顺便说一下,其中一些页面还具有自定义的动态内容(如表单),因此它们不完全是HTML/静态的。感谢您的任何建议。

    2 回复  |  直到 15 年前
        1
  •  2
  •   SMka    15 年前

    必须为页面标题创建“slug”。就像是“联系我们”并保存它

    然后使用Standart路由器功能

    routes.showarticles.type = "Zend_Controller_Router_Route_Regex"
    routes.showarticles.route = "articles(?:/([a-zA-Z\-]+))?"
    routes.showarticles.reverse = "articles/%s"
    routes.showarticles.defaults.controller = "posts"
    routes.showarticles.defaults.action = "show-articles"
    routes.showarticles.map.1 = "slug"
    routes.showarticles.defaults.slug = slug
    

    像这样的东西

    或者u可以像stackoverflow一样,包括url中的page_id和可选的slug部分 喜欢

    http://zagon.org/articles/ku-ka-re-ku/56/edet-kujvashev-na-velosipede-7

    http://zagon.org/articles/ku-ka-re-ku/56

    编辑

    protected function _initRoutes()
    {
        if ($this->hasOption('routes')) {
            $this->bootstrap('frontController');
            $frontController = $this->getResource('frontController');
            /* @var $router Zend_Controller_Router_Rewrite */
            $router = $frontController->getRouter();
            $router->addConfig(new Zend_Config($this->getOption('routes')));
        }
    }
    
        2
  •  0
  •   Jay Zeng    15 年前

    您可以使用Zend路由或mod_rewrite来实现这一点。 我的逻辑是

    - If URL exists, route to the matched one
    - If URL does not exist, check if space is present 
            - Replace space with '-' (or other delimiter) then do the checking again. 
            - If no space is present, display a 404 or redirect to front page.