[英]Get full site home URL in Kohana 3
I installed Kohana (in a "kohana" directory in my xampp public folder) and I'm trying to get the full base URL with the domain and protocol. 我安装了Kohana(在我的xampp公共文件夹中的“kohana”目录中),我正在尝试使用域和协议获取完整的基本URL。
When I try: 当我尝试:
url::base();
I only get /kohana/
back as a result, but want http://localhost/kohana/
instead. 结果我只得到
/kohana/
back,但是想要http://localhost/kohana/
。
Is it possible to do this in Kohana, or must I use standard PHP? 是否可以在Kohana中执行此操作,还是必须使用标准PHP?
You don't have to extend anything, just use URL::site
with the protocol
parameter: 您不必扩展任何内容,只需使用带有
protocol
参数的URL::site
:
$base_url = URL::site(NULL, TRUE);
This will generate a base URL with the current protocol. 这将生成具有当前协议的基本URL。 If you want to use a specific protocol:
如果要使用特定协议:
$base_url = URL::site(NULL, 'http');
No need to reinvent the wheel here! 无需在这里重新发明轮子!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.