/ Published in: PHP
The below code helps you move your site assets (images, css, javascript) to a public folder inside the application directory of CodeIgniter.
One thing you'll need to do is define ASSETPATH to be the path to the location of your public items. For myself, I set this to system/application//public/.
See some of my other snippets to get some background on the subdomain part of that path.
One thing you'll need to do is define ASSETPATH to be the path to the location of your public items. For myself, I set this to system/application//public/.
See some of my other snippets to get some background on the subdomain part of that path.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php # # Image Helper # { function image($src = '', $index_page = FALSE) { { } if ( ! $src['alt'] ) { $src['alt'] = ''; } $img = '<img'; foreach ($src as $k=>$v) { { $img .= ' src="'.ASSETPATH.'/images/'.$v.'" '; } else { $img .= " $k=\"$v\" "; } } $img .= '/>'; return $img; } } # # CSS Helper # { function attach_stylesheet($file, $media = "screen") { $src = ASSETPATH . '/stylesheets/'; $css = '<link rel="stylesheet '; $css .= 'href="'.$src.'" '; $css .= 'type="text/css" '; $css .= 'media="'.$media.'" '; $css .= '/>'; return $css; } } # # Javascript Helper # { function attach_javascript($file) { $src = ASSETPATH . '/javascripts/'; $script = '<script type="text/javascript" '; $script .= 'src="'.$src.'"></script>'; return $script; } }