To solve my problem, I created helper functions for loading assets. And here is my code deployed in my application. PS: At first I planned a good / flexible directory structure.
[ some_helper.php ]
/* * Created: 2017/12/14 00:28:30 * Updated: 2017/12/14 00:28:39 * @params * $url_structure = 'assets/js/%s.js' * $files = ['main.min', 'social'] * $echo = FALSE * */ function load_js($files = [], $url_structure = NULL, $version = '1.0', $echo = FALSE){ $html = ""; foreach ($files as $file) { if($url_structure){ $file = sprintf($url_structure, $file); } $file_url = base_url($file); $html .= "<script src=\"{$file_url}?v={$version}\"></script>"; } if($echo) { echo $html; } return $html; } /* * Created: 2017/12/14 00:28:48 * Updated: 2017/12/14 00:28:51 * @params * $version = '1.0' // Later load from configuration * $url_structure = 'assets/js/%s.css' * $files = ['main.min', 'social'] * $echo = FALSE * */ function load_css($files = [], $url_structure = NULL, $version = '1.0', $echo = FALSE){ $html = ""; foreach ($files as $file) { if($url_structure){ $file = sprintf($url_structure, $file); } $file_url = base_url($file); echo "<link rel=\"stylesheet\" href=\"{$file_url}?v={$version}\">"; } if($echo) { echo $html; } return $html; }
Then called in view
[ some_view.php ]
$css = [ 'path' => 'assets/css/%s.css', 'files' => ['bootstrap.min','style'] ]; load_css($css['files'], $css['path'], '1.0', TRUE);
Hope this helps someone. In the case of OP $css['path'] = 'application/assets/css/%s.css'; the trick will be performed.
Updated Github code, which I will continue to update.
source share