如何获得基本Url在cakephp? [英] How to get the base Url in cakephp?

查看:88
本文介绍了如何获得基本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

这篇关于如何获得基本Url在cakephp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆