I’m using the cakephp url HTML helper like following:
<?php echo $this->Html->url(array('controller' => 'communities', 'action' => 'view'), true); ?>
but, it’s returing the following url: http://127.0.0.1:8888/communities/view
where is coming this 127.0.0.1:8888 ? How can I change that?
PS: If I remove the ‘true’ for second parameter, this isn’t happens.
The
Html::url()method’s first argument is the CakePHP URL array, and the second is a boolean value that indicates whether or not the full (absolute) URL should be returned.In your case,
displays the URL
http://127.0.0.1:8888/communities/viewbecause you’ve indicated that you want the full, absolute URL by setting the second argument to true, you’re running the site on localhost (IP address 127.0.0.1) and using port 8888 (the :8888 part).
If you used
you would see only
/communities/viewbecause the second argument is not set and it defaults to false.When the second argument is set to true, it always displays the full, absolute URL based on the domain that the app is running on. So when you upload your site to your production environment,
Html::url()would returnhttp://www.example.com/communities/view, for example.If you check the API, you might not be able to find the url method on the HtmlHelper’s page. This is because the HtmlHelper actually inherits the method from the Helper class (http://api.cakephp.org/file/cake/libs/view/helper.php#method-Helperurl).