kohana v3:针对不同的子域使用不同的模板 [英] kohana v3: using different templates for different subdomains

查看:48
本文介绍了kohana v3:针对不同的子域使用不同的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个kohana v3应用程序.指向此应用程序的2个子域.如果应用程序使用subdomain2.example.com调用,我必须设置的是kohana使用不同的模板吗?

I have a kohana v3 app. 2 subdomains pointing to this app. what I have to setup that kohana uses a different template if the app called with subdomain2.example.com?

目前(从subdomain1和subdomain2)进行的所有调用均使用标准模板:"templates/default"

at the moment all calls (from subdomain1 and subdomain2) use the standard template: 'templates/default'

谢谢!

丹尼尔

推荐答案

首先,从 $ _ SERVER ['SERVER_NAME'] 获取子域名:

list($subdomain) = explode('.', $_SERVER['SERVER_NAME'], 2);

然后根据子域选择要使用的模板:

Then choose what template to use based on the subdomain:

// Replace this with a switch() statement if you want to choose another way
$this->template = 'templates/'.$subdomain;

在调用 parent :: before()之前,应将以上代码放置在 Controller :: before()方法中.假设您正在使用 Controller_Template 或其扩展名.

The above code should be placed in the Controller::before() method before you call parent::before(). This assumes that you are using the Controller_Template or an extension of it.

这篇关于kohana v3:针对不同的子域使用不同的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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