Skip to content


Kohana Media Controller

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.

view the source here

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');

Posted in Code, Components.

Tagged with , , , , , .


4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. xrado says

    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

  2. Kerk says

    thanks. fixed

  3. Dave Stewart says

    Hey kerkness, are you supposed to extend this controller in order to use its functionality?

  4. Kerk says

    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.



Some HTML is OK

or, reply to this post via trackback.



close