How to get the base Url in cakephp?

后端 未结 5 1319
遇见更好的自我
遇见更好的自我 2021-01-02 02:13

I\'m using Html Helper css() method to link my stylesheets just like this: Html->css(\'reset.css\');?> but what if my

相关标签:
5条回答
  • 2021-01-02 02:25

    There are a few different ways to get the base path. I use

    echo $this->webroot; //Note: auto appends trailing slash
    
    0 讨论(0)
  • 2021-01-02 02:34

    Use this for baseurl

    echo $this->html->url('/', true);
    
    0 讨论(0)
  • 2021-01-02 02:36

    On a related note.

    If you need the theme url you can do this:

    $this->webroot.'theme/'.$this->theme
    
    0 讨论(0)
  • 2021-01-02 02:37

    The exact same command should work:

    <?php 
    echo $this->Html->css('reset.css');
    ?>
    

    It automatically adds the path to the CSS folder if the given path 'reset.css' doesn't start with a slash.

    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
    
    0 讨论(0)
  • You must format: WWW_ROOT . DS . 'css/file.css';

    0 讨论(0)
提交回复
热议问题