5

I am following documentation http://docs.kohanaphp.com/general/helpers . But these steps are not working in kohana 3.1 . I can't find any documentation about helper in kohana 3.1 . how I can create my own helper class in kohana ?

Vivek Goel
  • 22,942
  • 29
  • 114
  • 186

2 Answers2

12

The accepted answer isn't really true!

Helpers do exist in Kohana 3.1.

http://kohanaframework.org/3.1/guide/kohana/helpers

Helpers are different from libraries in that they use static methods, the class does not have to be initiated for them to be used.

i.e. to call the URL helper class and run the base method you would simply do:

$foo = URL::base();

To extend the URL helper you would create a class in APPPATH/application/classes/ called url.php like:

class URL extends Kohana_URL {
    public static function bar()
    {
        // Do your magic
    }
}

And then again simply call it like so:

$foo = URL::bar();

8

There's no such thing as a helper in Kohana 3/3.1

You create a class and use it as you normally would in a PHP application.

The only requirements are that classes go into the classes directory and underscores in the class name are equal to directory separators. For example

class HTML_Helper

would be placed into

classes/html/helper.php

Then it's a simple case of using the class as your normally would.

The Pixel Developer
  • 13,282
  • 10
  • 43
  • 60