Created
June 1, 2013 23:09
-
-
Save thinkadoo/5692016 to your computer and use it in GitHub Desktop.
Module Assets Controller for CIBonfire HMVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!defined('BASEPATH')) | |
exit('No direct script access allowed'); | |
class assets extends CI_Controller { | |
function __construct() { | |
parent::__construct(); | |
//---get working directory and map it to your module | |
$word = 'public'; | |
$string = getcwd(); | |
$string = str_replace($word, "", $string); | |
$parts = $this->uri->segments; | |
$file = $string . 'application/modules/' . $parts[3] .'/'. $parts[2] .'/'. $parts[4] .'/'. $parts[5]; | |
$path_parts = pathinfo( $file); | |
//---set the type for the headers | |
$file_type= strtolower($path_parts['extension']); | |
if (is_file($file)) { | |
//----write propper headers | |
switch ($file_type) { | |
case 'css': | |
header('Content-type: text/css'); | |
break; | |
case 'js': | |
header('Content-type: text/javascript'); | |
break; | |
case 'json': | |
header('Content-type: application/json'); | |
break; | |
case 'xml': | |
header('Content-type: text/xml'); | |
break; | |
case 'pdf': | |
header('Content-type: application/pdf'); | |
break; | |
case 'jpg' || 'jpeg' || 'png' || 'gif': | |
header('Content-type: image/'.$file_type); | |
readfile($file); | |
exit; | |
break; | |
} | |
include $file; | |
} else { | |
show_404(); | |
} | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment