CodeIgniter Forums
How come you can't use base_url in a config file? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How come you can't use base_url in a config file? (/showthread.php?tid=49251)



How come you can't use base_url in a config file? - El Forum - 02-12-2012

[eluser]dallen33[/eluser]
Just curious. I wanted to do something like:
Code:
$config['assets'] = base_url().'assets/';
Is there another way of doing this?


How come you can't use base_url in a config file? - El Forum - 02-13-2012

[eluser]InsiteFX[/eluser]
Create an assets_helper.php

Here is a start:
Code:
if ( ! function_exists('asset_url'))
{  
    function asset_url()
    {
        // the helper function doesn't have access to $this, so we need to get a reference to the
        // CodeIgniter instance.  We'll store that reference as $CI and use it instead of $this
        $CI =& get_instance();
      
        // return the asset_url
        return base_url() . $CI->config->item('asset_path');
    }
}

if ( ! function_exists('css_url'))
{  
    function css_url()
    {
        // the helper function doesn't have access to $this, so we need to get a reference to the
        // CodeIgniter instance.  We'll store that reference as $CI and use it instead of $this
        $CI =& get_instance();
      
        // return the asset_url
        return base_url() . $CI->config->item('css_path');
    }
}

if ( ! function_exists('js_url'))
{  
    function js_url()
    {
        // the helper function doesn't have access to $this, so we need to get a reference to the
        // CodeIgniter instance.  We'll store that reference as $CI and use it instead of $this
        $CI =& get_instance();
      
        // return the asset_url
        return base_url() . $CI->config->item('js_path');
    }
}

Now set your paths in a config file...
Code:
$config['asset_path'] = 'assets/';
$config['css_path']   = 'assets/css/';
$config['js_path']    = 'assets/js/';