Create links to resources in Kohana

I use in kohana myown helper that create pathes to resorces such as images, swf, swf, js etc. You can use it too it’s simple. There is it’s source:

class urlpath_Core {
private static $_misc_dir = "misc/";
public static function css($name)
{
return url::site() . self::$_misc_dir . "css/" . $name;
}
public static function js($name)
{
return url::site() . self::$_misc_dir . "js/" . $name;
}
public static function img($name)
{
return url::site(self::$_misc_dir . "img/" . $name);
}
public static function pic($name)
{
return url::site() . self::$_misc_dir . "pic/" . $name;
}
public static function swf($name)
{
return url::site() . self::$_misc_dir . "swf/" . $name;
}
}

Then I created folder in site’s root called `misc` and subdirectories for ones:

  • css – all styles for pages
  • img – static images for design (logo, backgrounds etc)
  • js – javascript’s scripts
  • pic – this directory contain pictures uploaded by users. in other words there are dynamically added pictures
  • swf – there are my flash and configs of flash files

So now there are simple way to create path to resource from template:

<img src="<?php echo urlpath::img('logo.png') ?>" alt="" />

It’ll printed something like:

<img src="http://yperevoznikov.com/misc/img/logo.png" alt="" />

If you have any suggestions – do not hesitate and write comments.

Books to read

Leave a Reply

Your email address will not be published. Required fields are marked *