开发者

url helper in cake is returning 127.0.0.1:8888? Why?

开发者 https://www.devze.com 2023-04-09 04:51 出处:网络
I\'m using the cakephp url HTML helper like following: <?php echo $this->Html->url(array(\'controller\' => \'communities\', \'action\' => \'view\'), true); ?>

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?

P开发者_如何学编程S: 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,

<?php 
echo $this->Html->url(array('controller' => 'communities', 'action' => 'view'), true); 
?> 

displays the URL http://127.0.0.1:8888/communities/view because 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

<?php 
echo $this->Html->url(array('controller' => 'communities', 'action' => 'view')); 
?> 

you would see only /communities/view because 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 return http://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).


you are returning controller url address. second parameter says, that path should be relative. controller address is "communities/view" but with second parameter (relative=false) it is http://127.0.0.1:8888/communities/view

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号