To get the complete URL from the hostname, write the following command,
echo $this->Html->url(null, true);
Here, we set the full option to true. So, we get the full scheme, hostname, and project path. Suppose the above command gives the following result,
http://localhost/project/controller/action/1