在CakePHP中处理别名URL [英] Dealing with Alias URLs in CakePHP

查看:107
本文介绍了在CakePHP中处理别名URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cakephp重写我们的公司网站,需要找到一种方法来执行以下操作:

I am rewriting our company website in cakephp, and need to find a way to do the following:


  1. 用户进入我们的网站通过使用促销别名URL的一个

    已针对特定的
    媒体广告(杂志,网络
    促销等)预生成

  2. 针对别名URL的
    数据库检查URL,如果存在
    别名,则将特定的
    跟踪代码写入
    会话。

我考虑过几个选项,其中没有一个适合这个目的。它们是:

I have considered several options, none of which seem suitable for this purpose. They are:


  1. 将查找脚本放在appcontroller的
    beforeFilter()中,因此
    每个
    控制器。 (写一个会话值
    ,所以它只执行一次。)

    • 此选项仅适用于现有轮廓,并给出
      Cake'missing controller'

做一个地方在应用程序流,我可以把这个查找/跟踪脚本,我是相当新的蛋糕,所以我被困住。

I really could do with a place in the application flow where I can put this lookup/tracking script, and I'm fairly new to cake so I'm stumped.

编辑:此外,我知道一个叫做promo的子文件夹很容易做到这一点,但我有很多从旧站点的遗留URLS,需要处理

Also, I know that a subfolder called say 'promo' would easily do this, but I have a lot of legacy URLS from our old site, that need handling too.

推荐答案

一个非常有趣的问题。我想我会使用项目#3。这不是真的凌乱 - 毕竟,这通常是由我的东西中的页面控制器处理。这就是我将如何处理它 - 硬编码路由到你的控制器在routes.php,然后有一个matchall路由,将为您的促销代码工作。这允许你保留旧的URL,以及使用很多标准的蛋糕的东西(你可能只需要明确地陈述每个控制器路由,而不是这样的家务...)另外,它会让你做一些酷的东西与404错误 - 你可以在那里尝试,弄清楚他们试图去,所以你可以超级你的404的一些逻辑。

A very interesting question. I think I would use item #3. It's not really that messy -- after all, this typically is handled by the pages controller in my stuff. That's how I'd handle it - hardcode your routes to your controllers in routes.php, then have a matchall route that will work for your promo codes. This allows you to keep legacy URLs, as well as use a lot of the standard cake stuff (you probably will just have to explicitly state each of your controllers routes, not such a chore...) Additionally, it will let you do some cool stuff with 404 errors -- you can put some logic in there to try and figure out where they were trying to go, so you can superpower your 404's.

这篇关于在CakePHP中处理别名URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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