CodeIgniter的资产助手
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeIgniter的资产助手相关的知识,希望对你有一定的参考价值。
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.
<?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; } }
以上是关于CodeIgniter的资产助手的主要内容,如果未能解决你的问题,请参考以下文章