Here is a Media Controller I put together for my own Kohana projects. This controller will server valid css, javascript, png, jpeg or gif files that are in your Kohana application/views/media folder.
Usage
- save the source code linked above as media.php and place it in your application/controllers/ folder
- place your css files in the folder application/views/media/css/
- place your js files in the folder application/views/media/js/
- place your images in the folder application/views/image/
You can now load your files easily using Kohana helpers. NOTE: using file extensions when calling files is optional
echo html::stylesheet( array('media/css/style'), array('screen') );
echo html::script(array('media/js/mootools'), FALSE);
echo html::image('media/image/loading');
first big thx for the script!
i found a small bug in function display_file:
header(’Content-Type: ‘ . Kohana::config(”mimes.$ext”));
it should be header(’Content-Type: ‘ . reset(Kohana::config(”mimes.$ext”)));
other whise it returns Content-Type:array
thanks. fixed
Hey kerkness, are you supposed to extend this controller in order to use its functionality?
Hi Dave,
You can just save the file as media.php in your controllers folder. You would use the examples most likely in your main template view file, or at least what ever view file has your html header.