如何获得基本Url在cakephp?
我使用 Html Helper css()
方法链接我的样式表,如下所示:<?php echo $ this-> Html-> css('reset.css');?>
但是如果我的CakePHP应用程序通过 http://site.domain之外的路径访问。 com
,即 http://site.domain.com/my_app
I'm using Html Helper css()
method to link my stylesheets just like this: <?php echo $this->Html->css('reset.css');?>
but what if my CakePHP app is accessed through a path other than http://site.domain.com
, i.e. http://site.domain.com/my_app
完全相同的命令应该可以工作:
The exact same command should work:
<?php
echo $this->Html->css('reset.css');
?>
如果给定路径'reset,它会自动将路径添加到CSS文件夹.css'
不以斜杠开头。
It automatically adds the path to the CSS folder if the given path 'reset.css'
doesn't start with a slash.
顺便说一句,如果你需要在Cake中获取基本URL,可以使用 Router
class:
By the way, if you do need to get the base url in Cake, you can use the Router
class:
//with http://site.domain.com/my_app
echo Router::url('/') //-> /my_app
echo Router::url('/', true) //-> http://site.domain.com/my_app