[eluser]webdezzo[/eluser]
Ok all,
Going off of the real rlee's post, I successfully created the following helper, that works like a charm for what I am doing. Figured I would toss a write up on it for everyone to see! Weeeeee!
First,
In order to keep all of my custom config settings seperate, I created an external config file named config/paths.php which contains:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Front End Paths
|--------------------------------------------------------------------------
| base_url =
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://www.your-site.com/
|
| Add base_url prior to the path you are setting
|
*/
$config['image_path'] = "images";
$config['css_path'] = "css";
$config['js_path'] = "js";
$config['flash_path'] = "flash";
?>
Then, I created a path_helper.php file within the helper directory that contains the following:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
* @author Rick Ellis
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeignitor.com/user_guide/license.html
* @link http://www.codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* CodeIgniter PATH Helpers
*
* @package CodeIgniter
* @subpackage Helpers
* @category Helpers
* @author Todd Perkins (with the recommendation of the real rlee
* and others from the CI Forums)
* @link http://www.undecisive.com
*/
// ------------------------------------------------------------------------
/**
* Path IMAGES
*
* Creates http://www.domain.com/images
* or whatever the image file path that is specified in config
*
* @access public
* @param string
* @return string
*/
function path_images()
{
$CI =& get_instance();
return base_url().$CI->config->slash_item('image_path');
}
// ------------------------------------------------------------------------
/**
* Path CSS
*
* Creates http://www.domain.com/css
* or whatever the css file path that is specified in config
*
* @access public
* @param string
* @return string
*/
function path_css()
{
$CI =& get_instance();
return base_url().$CI->config->slash_item('css_path');
}
// ------------------------------------------------------------------------
/**
* Path JS
*
* Creates http://www.domain.com/js
* or whatever the js file path that is specified in config
*
* @access public
* @param string
* @return string
*/
function path_js()
{
$CI =& get_instance();
return base_url().$CI->config->slash_item('js_path');
}
// ------------------------------------------------------------------------
/**
* Path FLASH
*
* Creates http://www.domain.com/flash
* or whatever the flash file path that is specified in config
*
* @access public
* @param string
* @return string
*/
function path_flash()
{
$CI =& get_instance();
return base_url().$CI->config->slash_item('flash_path');
}
// ------------------------------------------------------------------------
?>
I included the path helper in the autoload file:
Code:
$autoload['config'] = array('paths');
And whala! I can call my image path from within my views =)
Code:
<?= path_images() ?>
Also, my folder structure is just as suggested, root folder:
/images
/css
/flash
/js
this way, when I am calling any image assets from within a stylesheet, (that cannot contain php code) I can simply call /images/filename.jpg)
Hope this helps!
-undecisive