1. 在application/config/config.php 文件中

如图设置base_url 根路径, css_url css路径, js js路径,images images路径.

/*

|————————————————————————–

| Base Site URL

|————————————————————————–

|

| URL to your CodeIgniter root. Typically this will be your base URL,

| WITH a trailing slash:

|

| https://example.com/

|

*/

$config[‘base_url’] = “https://localhost/code/”;

$config[‘css_url’] = “https://localhost/code/system/application/views/css/”;

$config[‘js_url’] = “https://localhost/code/system/application/views/js/”;

$config[‘img_url’] = “https://localhost/code/system/application/views/images/”;

2. 在system/helpers/url_helper.php文件中

如下配置以上的路径:

// ————————————————————————

/**

* Base URL

*

* Returns the “base_url” item from your config file

*

* @access public

* @return string

*/

if ( ! function_exists(‘base_url’))

{

function base_url()

{

$CI =& get_instance();

return $CI->config->slash_item(‘base_url’);

}

}

/**

* CSS URL

*

* Returns the “CSS URL” item from your config file

*

* @access public

* @return string

*/

if (! function_exists(‘css_url’)) {

function css_url(){

$CI =& get_instance();

return $CI->config->slash_item(‘css_url’);

}

}

/**

* JS URL

*

* Returns the “JS URL” item from your config file

*

* @access public

* @return string

*/

if (! function_exists(‘js_url’)) {

function css_url(){

$CI =& get_instance();

return $CI->config->slash_item(‘js_url’);

}

}

/**

* IMAGE URL

*

* Returns the “IMAGE URL” item from your config file

*

* @access public

* @return string

*/

if (! function_exists(‘img_url’)) {

function css_url(){

$CI =& get_instance();

return $CI->config->slash_item(‘img_url’);

}

}

3. 在view层调用的时候 如下: