CodeIgniter框架 URL 设置

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:

|

|       http://example.com/

|

*/

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

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

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

$config[‘img_url’] = “http://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层调用的时候 如下:

Need a translation service?

Please enter your personal details and we will contact you shortly

Words translated by CCJK

146,096,379

Our Client Satisfaction

Rating for previous quarterr

4.00

Over 95% of our clients recommend our language services to others

Copyright © CCJK Technologies Co., Ltd. 2000-2019. All rights reserved.
TOP