【问题标题】:regenerating url in cf9/Coldbox在 cf9/Coldbox 中重新生成 url
【发布时间】:2010-06-04 17:31:40
【问题描述】:

您好,我想知道在使用 event.buildLink 时,在冷箱/CF9 中加载任何页面时是否有办法重新生成 URL?

目前我在使用 event.buildlink 时得到http://cawksd05.codandev.local:8080/entries/editor

但正确的 url 应该添加 /index.cfm 如下所示:

/index.cfm/entries/editor

有没有办法设置一次,在哪里设置,因为我很困惑在哪里为我的所有页面设置这个,以便 /index.cfm 在我执行 event.Buildlink 时添加 url 前缀。

谢谢 法希姆

// 一般属性 setUniqueURLS(false); setAutoReload(false);

// 基本地址 if(len(getSetting('AppMapping')) lte 1){ setBaseURL("http://#cgi.HTTP_HOST#/index.cfm"); } 别的{ setBaseURL("http://#cgi.HTTP_HOST#/#getSetting('AppMapping')#/index.cfm"); }

// 你的申请路线 格式约束 = {format="(xml|json)"};

addRoute(pattern="/api/:format/tasks/completed",handler="tasksAPI",action="list",constraints=formatConstraints,completed=true); addRoute(pattern="/api/:format/tasks",handler="tasksAPI",action="list",constraints=formatConstraints); addRoute(pattern="/api/:format?",handler="tasksAPI",action="invalid");

addRoute(pattern="/tasks/list/:status?",handler="tasks",action="index"); addRoute(pattern=":handler/:action?");

【问题讨论】:

    标签: url coldfusion url-routing coldfusion-9 coldbox


    【解决方案1】:

    不,setnextevent 是 3.0 中唯一应该使用的方法,其他的 setnextRoute 和 relocate() 现在已弃用。

    如果您对 Route.cfm 进行了更改,请确保重新初始化应用程序以使更改生效。

    index.cfm?fwreinit=1

    如果进行更改,他们通常会忘记重新启动应用程序。

    【讨论】:

      【解决方案2】:

      听起来你需要在 /config/Routes.cfm 文件中设置 baseURL

      // Base URL
      if( len(getSetting('AppMapping') ) lte 1){
          setBaseURL("http://#cgi.HTTP_HOST#/index.cfm");
      }
      else{
          setBaseURL("http://#cgi.HTTP_HOST#/#getSetting('AppMapping')#/index.cfm");
      }
      

      对比

      // Base URL
      if( len(getSetting('AppMapping') ) lte 1){
          setBaseURL("http://#cgi.HTTP_HOST#/");
      }
      else{
          setBaseURL("http://#cgi.HTTP_HOST#/#getSetting('AppMapping')#/");
      }
      

      【讨论】:

      • 嗨 Aaron 感谢这是我在 routes.cfm 中设置的内容,但是当我在另一个处理程序中使用 setNextEvent 或 buildlink 时,它不会添加包含 index.cfm 的基本 url。我会附上代码给你看。
      • 嗨亚伦,我的代码已添加到 routes.cfm 的页面顶部。
      • 还请注意,如果我将 fwreinit=1 添加到我要发布的 url 中,则链接可以正常工作,但没有这个,基本 url 不正确,即没有 index.cfm。
      • 尝试 setNextRoute() 而不是 setNextEvent。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2021-07-25
      • 2013-12-19
      • 1970-01-01
      • 1970-01-01
      • 2020-03-08
      • 1970-01-01
      相关资源
      最近更新 更多