CakePHP 根据域加载不同的布局/数据?

发布于 2024-10-15 17:34:29 字数 700 浏览 6 评论 0原文

我需要运行 2 个站点,一个面向高端客户,一个面向低端客户。

他们俩几乎做同样的事情,但看起来不同。例如,他们可能都有产品 A,但价格和描述(无重复内容)会不同。

然而,在大多数情况下,他们会有不同的产品,高端站点使用高端产品,低端站点使用低端产品。

如果两个站点都使用相同的底层结构会更容易,因此不必重复许多重叠的部分。尤其是在变化期间。但必要时需要允许每个站点使用不同的逻辑。

因此,如果我将 2 个不同的域(让它们称为 highend.com 和 lowend.com)指向同一服务器。处理这个问题的最佳方法是什么?

我应该/可以确定 app_controller 中使用的域并指定要使用的布局或设置子控制器要使用的变量吗?如何?

有没有办法可以为数据库中的某些字段添加前缀。例如,如果有一个 products 表以及一个 products.highend_nameproducts.lowend_name 字段。然后在代码中只需引用 Product.name 但根据使用的域,使用正确的域。但对于像 style_number 这样的重叠字段,没有前缀,只有 products.style_number 因为两种方式都是相同的。有没有办法设置这样的东西?如何?

做这样的事情最好的方法是什么?是否有不同的框架可以更好地处理这个问题?

I need to run 2 sites, One for high end customers and one for low end customers.

They both pretty much do the same thing but look different. For example they both might have product A, but the price and description (no duplicate content) will be different.

However, for the most part, they will have different products, high end products for the high end site and low end products for the low end site.

It is easier if both sites use the same underlying structure, so the many overlapping parts won't have to be duplicated. Especially during changes. But it needs to allow for different logic per site when necessary.

So if I point 2 different domains (lets call them highend.com and lowend.com) to the same server. What is the best way to handle this?

Should/Can I determine what domain is being used in the app_controller and specify which layout to use or set a variable to be used by the child controllers? How?

Is there a way I can prefix some fields in the database. For example, if there is a products table and a products.highend_name and a products.lowend_name fields. Then in the code just refer to Product.name but depending on which domain is used, use the correct one. But for overlaping feilds like style_number there is no prefix just products.style_number since its the same either way. Is there a way to set something like this up? How?

Whats the best way to go about doing something like this? Is there a different framework that could handle this better?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福%小乖 2024-10-22 17:34:29

在控制器中:

$host = $_SERVER['SERVER_NAME'];
if($host=='www.posh.com')
{
    $this->layout = 'posh';
}
elseif($host=='www.cheap.com')
{
    $this->layout = 'cheap';
}
else
{
    $this->layout = 'default';
}

In the controller:

$host = $_SERVER['SERVER_NAME'];
if($host=='www.posh.com')
{
    $this->layout = 'posh';
}
elseif($host=='www.cheap.com')
{
    $this->layout = 'cheap';
}
else
{
    $this->layout = 'default';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文