7

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.

When I try:

url::base();

I only get /kohana/ back as a result, but want http://localhost/kohana/ instead.

Is it possible to do this in Kohana, or must I use standard PHP?

random
  • 9,774
  • 10
  • 66
  • 83
Marek
  • 71
  • 1
  • 2

1 Answers1

12

You don't have to extend anything, just use URL::site with the protocol parameter:

$base_url = URL::site(NULL, TRUE);

This will generate a base URL with the current protocol. If you want to use a specific protocol:

$base_url = URL::site(NULL, 'http');

No need to reinvent the wheel here!

shadowhand
  • 3,202
  • 19
  • 23
  • Ah, I learned something. My (wrong) answer wrongfully assumed I had to set it all up in config (which I did for Kohana 2.3) – alex Jul 23 '10 at 04:37
  • why do I have to use protocol parameter? how protocol is related to full url showing? – Shiplu Mokaddim Sep 27 '13 at 06:41
  • The problem is it adds `/index.php/`to the end (even though I use clean urls (http://kohanaframework.org/3.3/guide/kohana/tutorials/clean-urls)). – Ivan Feb 19 '14 at 02:58