How to get base url in CodeIgniter 2.*

前端 未结 5 1178

In config.php

$config[\'base_url\'] = \'http://localhost/codeigniter/\';

In View



        
相关标签:
5条回答
  • 2020-12-13 18:10

    To use base_url() (shorthand), you have to load the URL Helper first

    $this->load->helper('url');
    

    Or you can autoload it by changing application/config/autoload.php

    Or just use

    $this->config->base_url();
    

    Same applies to site_url().

    Also I can see you are missing echo (though its not your current problem), use the code below to solve the problem

    <link rel="stylesheet" href="<?php echo base_url(); ?>css/default.css" type="text/css" />
    
    0 讨论(0)
  • 2020-12-13 18:19

    I know this is very late, but is useful for newbies. We can atuload url helper and it will be available throughout the application. For this in application\config\autoload.php modify as follows -

    $autoload['helper'] = array('url'); 
    
    0 讨论(0)
  • 2020-12-13 18:20

    You need to load the URL Helper in order to use base_url(). In your controller, do:

    $this->load->helper('url');
    

    Then in your view you can do:

    echo base_url();
    
    0 讨论(0)
  • 2020-12-13 18:28

    You need to add url helper in config/autoload

    $autoload['helper'] = array('form', 'url', 'file', 'html'); <-- Like This
    

    Then you can use base_url or any kind of url.

    0 讨论(0)
  • 2020-12-13 18:32

    Just load helper class

    $this->load->helper('url');
    

    thats it.

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